REST サービスでヘッダー値を渡すために、AJAX jQuery で beforeSend を使用しました。ヘッダー値は 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では機能しません。??
前もって感謝します。