<script>
(function(){
var searchURL = 'http://en.wiktionary.org/wiki/search';
$.ajax({
type: "GET",
url: searchURL,
dataType: "jsonp",
cache: false,
async:false,
success: function(responseData, textStatus, XMLHttpRequest){
iframe(responseData);
}
});
})();
</script>
我将此脚本添加到我的 html 文件中,它显示以下错误,在控制台中复制粘贴该函数也显示相同的错误。
Uncaught SyntaxError: Unexpected token <
Resource interpreted as Script but transferred with MIME type text/html
谁能帮我解决这个问题,我使用的是 Chrome 浏览器。
最佳答案
您无法通过 AJAX 请求任意页面,并且 jsonp 并不能神奇地实现这一点。您需要使用 Wiktionary API .
网址为http://en.wiktionary.org/w/api.php
。
$.ajax({
url: 'http://en.wiktionary.org/w/api.php',
dataType: 'jsonp', // will automatically add "?callback=jqueryXXX"
cache: true, // the API complains about the extra parameter
data: { // the parameters to add to the request
format: 'json',
action: 'query',
titles: 'test'
},
success: function(data){
console.log(data);
}
});
关于javascript - 未捕获的语法错误 : Unexpected token < , ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16722264/