0
 jsonp = (url, callback) => {
        var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random());
        window[callbackName] = function(data) {
            delete window[callbackName];
            document.body.removeChild(script);
            callback(data);
        };

        var script = document.createElement('script');
        script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;
        document.body.appendChild(script);
    }

componentDidMount() {
 this.jsonp('https://www.naver.com', function(data) {
            alert(data.meta.description);
        });
}

But I get:

Uncaught SyntaxError: Unexpected token < error...

How can I resolve this?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
kekeee
  • 359
  • 2
  • 5
  • 12

1 Answers1

-1

In your .babelrc file

 {
    "presets":[
        "react-app"
    ]
}

And then npm install --save-dev babel-preset-react-app

This is what create react app uses and is mostly updated to handle the latest syntax.

Nitish Phanse
  • 552
  • 1
  • 9
  • 16
  • That will not change the HTML document at `https://www.naver.com` into JSONP. It will still be HTML. – Quentin Dec 24 '19 at 11:34