来自$ .ajax调用的Jquery HTTP状态

时间:2014-01-23 15:51:30

标签: jquery ajax cross-domain

以下是我在HTML页面中进行的AJAX(跨域)调用。

    var deffered = $.ajax({
    url: serviceURL,        
    type: "POST",
    async: true,
    crossDomain: true,
    contentType: "text/plain",
    dataType: "jsonp",
    origin:window.location.protocol + "//" + window.location.host,
    timeout:5000,
    beforeSend: function ( xhr ) {
        xhr.setRequestHeader('Content-Type', 'text/plain');
        xhr.setRequestHeader('Access-Control-Allow-Methods', 'POST,GET,PUT, DELETE, OPTIONS');
        //xhr.setRequestHeader('Access-Control-Request-Headers', 'X-Requested-With');
        xhr.setRequestHeader('Access-Control-Allow-Origin','*');
        xhr.setRequestHeader('Access-Control-Allow-Headers','Content-Type,X-Requested-With');
        xhr.withCredentials = true;
    }

现在我遇到的问题是每当AJAX调用失败时,我都没有得到预期的HTTP状态代码。它始终为零(0)。我无法对服务器端代码进行任何更改。因此,在这种情况下,有任何解决方案可以在出现故障时获取404,500或任何其他HTTP代码等HTTP状态代码。如果成功,我可以将HTTP代码设置为200。

有什么想法吗?

0 个答案:

没有答案