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);
});
}
,但我得到:未捕获的SyntaxError:意外的标记<
Uncaught SyntaxError: Unexpected token < error...
我怎样才能解决这个问题?
你会得到哪一行错误?我在上面的代码片段中没有看到任何“<”。 – Nisarg
错误发生在'componentDidMount()'你必须写''function componentDidMount()' – adda82
你还没有忘记将代码从JSX转换成JS? – Amid