gpt4 book ai didi

javascript - jquery $ajax 没有按预期工作

转载 作者:行者123 更新时间:2023-11-30 07:26:46 25 4
gpt4 key购买 nike

我必须执行跨域请求并使用 $.ajax 函数从 url 中获取内容。但是下面的代码只显示第一个警报,即警报(myUrl),之后执行停止。不显示第二个警报。我不知道我写的代码有什么问题。有人可以告诉我我在这里做错了什么吗?提前致谢。

function getContentFromUrl(){
var myUrl="http://icant.co.uk";
alert(myUrl);
$.ajax({
url: "http://query.yahooapis.com/v1/public/yql?" +
"q=select%20*%20from%20html%20where%20url%3D%22" +
encodeURIComponent(myUrl) + "%22&format=xml'&callback=?",
dataType: 'json',
data: data,
success: function () {
alert("***********"+data.results[0]);
if (data.results[0]) {
var htmlText = data.results[0];
var jsonObject = parseAndConvertToJsonObj(htmlText);
} else {
document.getElementById("displayerrors").innerHTML = "Could not load the page.";
}
},
error: function() {
document.getElementById("displayerrors").innerHTML = "Could not load the page.";
}
});
}

最佳答案

Same Origin Policy :

The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.

关于javascript - jquery $ajax 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11605782/

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