jQuery的阿贾克斯失败,甚至与HTTP 200个状态

问题描述:

正如标题最高审计机关,我有这样的Javascript代码:jQuery的阿贾克斯失败,甚至与HTTP 200个状态

$.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"); }); 

我的网络服务器发送这些数据:

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的认为请求失败了吗?

+0

是AJAX的呼叫服务器和同一IP的业务逻辑的执行服务器? – 2013-03-12 07:55:40

+0

我有一个不同于jQuery脚本的计算机上的hiawatha webserver。 hiawatha webserver通过FastCGI处理请求。 – Pascal 2013-03-12 08:03:11

作为您的jQuery脚本服务器和Web服务器是不同的,它应该是一个跨域问题。

您应该使用jsonp进行此通信。

下面就是一个例子,它可以帮助你

http://www.jquery4u.com/json/jsonp-examples/

也许你可以使用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"); 
    } 
}); 

编辑:跨域阿贾克斯真的不像人们希望的那么方便。