2013-02-21 166 views
1

我在這裏傳遞一個HTTP請求頭值通過jquery的AJAX call..It與IE僅工作和Firefox.The不工作AJAX調用本身在Firefox是沒有發生時xhr.setRequestHeader是存在於代碼xhr.setRequestHeader在Firefox中不工作,但在IE中工作?

var Call = function() { 
$.support.cors = true; 
var input = { 
      RefId: "111", LoginId: "222", Id: "33", FirstName: "aaa", LastName: "bbb" 
      }; 
var url = document.URL; 
$.ajax({ 
      type: "POST", 
      beforeSend: function (xhr) { 
      xhr.setRequestHeader("URL", url); 
      }, 
      url: "http://localhost:40780/Service.svc/Insertion", 
      data: JSON.stringify(Input), 
      contentType: "application/json", 
      dataType: "json", 
      success: function (response) { 
      alert(response); 
      }, 
      error: function (xhr, status, error) { 
      } 
     }); 
    } 

有什麼建議嗎?

回答

0

嗯,我想原因可能在這裏找到,順便客戶端和服務器處理CORS和預檢要求:從JQuery的

JQuery的$就

http://www.html5rocks.com/en/tutorials/cors/

CORS()方法可用於制定常規XHR和CORS 請求。關於JQuery實現的一些注意事項:

JQuery的CORS實現不支持IE的XDomainRequest對象。但有一些JQuery插件可以實現這一點。有關詳細信息,請參閱 http://bugs.jquery.com/ticket/8283。 如果瀏覽器支持CORS,則$ .support.cors布爾值將被設置爲true(在IE中返回false,參見上面的項目符號)。這可以通過 快速檢查CORS支持。

headers: { 
    // Set any custom headers here. 
    // If you set any non-simple headers, your server must include these 
    // headers in the 'Access-Control-Allow-Headers' response header. 
    }, 

希望這將有助於

相關問題