gpt4 book ai didi

javascript - 未捕获的语法错误 : Unexpected token < , ajax 调用

转载 作者:行者123 更新时间:2023-11-28 20:29:26 24 4
gpt4 key购买 nike

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com