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