[英]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.