我之前在AJAX中使用jQuery来传递REST服务中的标头值。 标题值在Internet Explorer 8中传递良好。但在Firefox中不传递标题值,并且不调用该服务。
jQuery AJAX beforeSend在Firefox浏览器中失败
这里是我的代码:
var postCall = function() {
$.support.cors = true;
var HFAssociateRefId = document.getElementById('MainContent_HFAssociateRefId').value;
var Input = {
AssociateRefId: HFAssociateRefId
};
alert(JSON.stringify(Input));
var url = document.URL;
var currentdate = new Date();
var datetime = (currentdate.getMonth() + 1) + "/"
+ currentdate.getDate() + "/"
+ currentdate.getFullYear() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
$.ajax({
type: "POST",
headers: { Accept: "text/plain; charset=utf-8", "Content-Type": "text/plain; charset=utf-8"
},
beforeSend: function (xhr, settings) {
xhr.setRequestHeader("Date", datetime);
xhr.setRequestHeader("URL", url);
},
url: "http://localhost:40680/LinkService.svc/TokenInsertion",
data: JSON.stringify(Input),
contentType: "application/json",
dataType: "json",
success: function (response) {
alert(response);
},
error: function (xhr, status, error) {
alert(status);
},
});
我也如本link指定调用XHR新的XMLHttpRequest尝试。 但它不适用于Firefox。 ??
在此先感谢。
在'beforeSend函数'中添加一个提醒并测试它,它工作与否? – 2013-02-21 05:38:06
@Rohan Kumar是的,警报值发生在beforeSend函数中。但是标题值不会被传递。 – kk1076 2013-02-21 05:56:27
如果它不起作用,那么你可以在数据中传递'data和url' – 2013-02-21 06:22:18