Uncaught SyntaxError: Unexpected token <

 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?


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.

链接地址: http://www.djcxy.com/p/46008.html

上一篇: 跨域JSONP请求返回未捕获的SyntaxError:意外的标记:

下一篇: 未捕获的SyntaxError:意外的标记<