正如标题所说,我有这个Javascript代码:
$.ajax({
type: "GET",
url: "http://192.168.20.249/test.brick",
dataType: "json"
}).done(function() { alert("success"); }).fail(function() { alert("error"); }).always(function() { alert("complete"); });我的data服务器发送这些数据:
200 OK
Date: Tue, 12 Mar 2013 07:49:51 GMT
Server: Hiawatha v8.8
Connection: keep-alive
Transfer-Encoding: chunked
Content-Type: application/json
{"Test": "Hello"}知道为什么jQuery认为请求失败了吗?
发布于 2013-03-12 16:46:39
由于您的jquery脚本服务器和web服务器不同,这应该是一个跨域的问题。
您应该使用jsonp进行此通信。
下面是一个可以帮助你的例子
http://www.jquery4u.com/json/jsonp-examples/
发布于 2013-03-12 16:43:27
也许你可以使用error回调来获得更多关于jQuery看到什么错误的信息?
$.ajax({
type: "GET",
url: "http://192.168.20.249/test.brick",
dataType: "json",
error: function(jqXHR, textStatus, errorThrown){
("error: " + textStatus); //Check all parameters in this callback
},
success: function(){
alert("success");
}
});编辑:跨域ajax并不像人们希望的那样方便。
https://stackoverflow.com/questions/15355902
复制相似问题