$ .ajax错误回调被调用而不是成功

时间:2014-07-02 18:14:03

标签: jquery ajax

我正在制作ajax get请求。我从服务器得到200 Ok响应。但是,正在调用错误回调而不是成功回调。

$.ajax({
    type: 'get',
    url: 'http://10.221.48.168/Publish/?fileId=1026',
    cache: false,
    success: function (data) {
        alert("Success");
    },
    error: function () {
        alert("error");
    }
});

的Fiddler 请求

GET http://10.221.48.168/Publish/?fileId=1026&_=1404324352691 HTTP/1.1    
Referer: http://localhost:60391/TntBulkUpload/Index    
Accept: */*
Accept-Language: en-US    
Origin: http://localhost:60391    
Accept-Encoding: gzip, deflate    
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)    
Host: 10.221.48.168    
DNT: 1    
Connection: Keep-Alive    
Pragma: no-cache

响应:

HTTP/1.1 200 OK    
Date: Wed, 02 Jul 2014 11:05:16 -0700    
Server: Mule Core/3.5.0    
X-MULE_SESSION: gAJeHB4    
X-MULE_ENCODING: UTF-8    
Content-Type: text/plain    
Content-Length: 37    
Connection: close    

/Publish/?fileId=1026&_=1404324352691

修改:浏览器控制台错误:

SEC7118: XMLHttpRequest for http://10.221.48.168/Publish/?fileId=1026&_=1404325311488 required Cross Origin Resource Sharing (CORS). 
SEC7120: Origin http://localhost:60391 not found in Access-Control-Allow-Origin header. 
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

1 个答案:

答案 0 :(得分:1)

您需要在返回成功或错误的应用程序上的Access-Control-Allow-Origin标头中添加一个条目(10.221.48.168/Publish/?fileId=1026& _ = 1404324352691)。

我不确定该应用程序使用的是哪种语言,但如果您使用的是ASP.NET,请参阅此处的精彩参考以启用CORS:http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api#enable-cors