我之前在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