gpt4 book ai didi

jQuery AJAX 状态 "200 OK",但没有数据响应

转载 作者:行者123 更新时间:2023-12-03 22:45:16 25 4
gpt4 key购买 nike

jQuery:

$.ajax({
url : url,
type : 'GET',
dataType: 'json',
data: {
'FN' : 'GetPages',
'PIN' : '7659'
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function(data) {
alert('succsess');
console.log('data', data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert('error');
console.log(xhr.status);
console.log(thrownError);
}
});

Firebug Firefox 网络

Firebug Error

发生了什么

AJAX“错误:”事件被触发,我的console.log输出是:

xhr.status -> 0

thrownError -> (empty String)

这正常吗?当我在浏览器中输入 URL 时,我会收到包含 JSON 内容的文件下载,这应该不是问题,对吧?

最佳答案

感谢@CrimsonChin,我知道这是同源策略问题

In computing, the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. 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.[1]

(来自 http://en.wikipedia.org/wiki/Same_origin_policy )

授予 JavaScript 客户端对资源的基本访问权限只需添加一个 HTTP 响应 header ,即:

Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: http://foo.example.com

(来自 http://enable-cors.org/ )

Ofc,将 JSON 响应转换为 JSONP响应也会起作用。谢谢@djakapm

关于jQuery AJAX 状态 "200 OK",但没有数据响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13525097/

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