2013-02-21 167 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. 
    }, 

希望这将有助于

相关问题