我在jQuery AJAX POST方法中調用了Rest服務。我需要在頭中傳遞兩個值。 Firefox既沒有將標題值傳遞給服務也沒有調用REST服務。
我的jQuery代碼在jQuery AJAX POST中傳遞標頭值firefox
var postCall = function() {
$.support.cors = true;
var HFAssoRefId = document.getElementById('MainContent_HFAssoRefId').value;
var Input = {
AssoRefId: HFAssoRefId
};
alert(JSON.stringify(Input));
var url = document.URL;
var name = "samuel";
$.ajax({
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("PartnerName", name);
xhr.setRequestHeader("URL", url);
},
url: "http://localhost:40680/Service.svc/TokenInsertion",
data: JSON.stringify(Input),
contentType: "application/json",
dataType: "json",
success: function (response) {
alert(response);
},
error: function (xhr, status, error) {
alert(status);
}
});
}
是否有任何其他的方法來傳遞jQuery的AJAX的標頭值。它可以在Internet Explorer 8中正常工作。如何使它與Firefox瀏覽器兼容?
我嘗試了其他方法發佈像這樣。 方法1:
$(document).ready(function() {
$("#button").click(function(){
var name1 = "samuel";
var url1 = document.URL;
$.post('http://localhost:41855/IntegrationCheck/Default.aspx', {
name : name1,
url : url1
},function (data) {
alert(data);
});
});
});
在AJAX的jQuery
和方法2:
function setHeader() {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader('Accept', '');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "text/xml;application/json");
xhr.setRequestHeader("PartnerName", name);
xhr.setRequestHeader("URL", url);
}
但標頭值就不傳遞和該服務沒有在Firefox調用。 任何建議..
你確實有幾個語法錯誤在你的第一個代碼片段,但他們應該做出它不在IE中工作,所以我假設他們只是在這裏輸入代碼的工件。 – 2013-02-22 08:07:56
'AssoRefId:HFAssoRefId後面的逗號,' 缺少括號來關閉'.ajax({''''關閉後'} – 2013-02-22 08:08:53
它不能解釋爲什麼其他兩個查詢不起作用:) – 2013-02-22 08:13:24