我在 AJAX jQuery 中使用 beforeSend 来传递 REST 服务中的标头值。标头值在 Internet Explorer 8 中可以很好地传递。但标头值在 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);
},
});
我还尝试将 xhr 称为此链接中指定的新 XMLHttpRequest 。但它在 Firefox 中不起作用。??
提前致谢。