[英]Uncaught syntax error: Unexpected token < , ajax call
<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 。
該URL是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);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.