2012-11-13 95 views
0

我在網上搜索了很多針對IE9 ajax跨域問題的解決方案,並且找不到任何解決方案。來自IE9的非常奇怪的jSON ajax響應

我使用的AJAX調用的URL看起來像這樣(這是跨域,因爲我的域名看起來像www.domain.com):

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

Ajax調用看起來是這樣的:(我有嘗試添加/刪除跨域/類型和任何我能想到的)

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

這是鉻可愛的響應(請求竟沒這段時間):

{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" 

}

(IE9的響應觸發SCRIPT1014: Invalid character的代碼時,我嘗試解析它作爲JSON,因爲它顯然不是一個JSON ...)

與「無運輸」有關嗎?有跨域問題?

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

我絕望 - 可有人建議

+2

如果它是一個跨域請求時不能使用數據類型: 'json',你必須使用dataType:'jsonp'或CORS –

+0

CORS是什麼意思?你能給我一個如何編寫它的例子嗎? – Alon

+0

它適用於chrome嗎?爲什麼它不適用於IE9 ? – Alon

回答

1

嘗試設置:?

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

,看看它是否有助於