0

我在网上搜索了许多针对 IE9 ajax 跨域问题的解决方案,但找不到任何解决方案。

我用于 ajax 调用的 url 看起来像这样(这是跨域,因为我的域看起来像 www.domain.com):

"http://some.domain.com/folder//api/12c63101-5d02-ab70-6e2a-4519ed75a0fd/rename?accept=json"

ajax 调用看起来像这样:(我尝试添加/删除 crossDomain/type 以及我能想到的任何东西)

$.ajax({
        url:url,
        dataType:'json',
        type: 'POST',
        crossDomain: true,
        success:function(data){}
        complete : function(data) {}})

这是来自 chrome 的一个可爱的响应(这次请求应该失败了):

 {errorCode: -3997, errorDescription: "[runtime][RECOVERABLE] failed, name [] taken", success: false, payload: null}

但这是来自 IE9 的奇怪反应

LOG: {
readyState : 0,
setRequestHeader : function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},
getAllResponseHeaders : function(){return s===2?n:null},
getResponseHeader : function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},
overrideMimeType : function(a){s||(d.mimeType=a);return this},
abort : function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this},
done : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
fail : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
progress : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
state : function(){return e},
isResolved : function(){return!!e},
isRejected : function(){return!!e},
then : function(a,b,c){i.done(a).fail(b).progress(c);return this},
always : function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this},
pipe : function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.re,
promise : function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a},
success : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
error : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
complete : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},
statusCode : function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},
status : 0,
statusText : "No Transport"

}

(当我尝试将其解析为 JSON 时,IE9 响应在代码中触发SCRIPT1014: Invalid character,因为它显然不是 JSON……)

与“无运输”有关吗?有跨域问题?

UTF-8?(已经声明$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});

我绝望了-有人可以建议吗?

4

1 回答 1

1

尝试设置:

jQuery.support.cors = true; // force cross-site scripting (as of jQuery 1.5)

看看它是否有帮助。

于 2012-11-14T02:06:32.460 回答