1
var username = 'xxxx';
var password = 'zzzz';
var xmlstring="<root><request><AADHAAR_ID>aaaaaaa</AADHAAR_ID><NAME>hhhhhhh</NAME><DOB></DOB><MOBILENO></MOBILENO><FLAG>QVVUSA==</FLAG><RESPONSE_CODE></RESPONSE_CODE><ERROR_CODE></ERROR_CODE><OTP></OTP><PIN></PIN><DEPT>aswww</DEPT><VENDORID>MTAwSFBN</VENDORID></request></root>";
function make_base_auth(username, password) {
var tok = username + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$.ajax({
type: "POST",
async: true,
dataType:"xml",
contentType: "application/xml",
url: 'http://test/test/test?reqXml='+xmlstring,
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(username, password));
},
success: function(){console.log('success');
alert('success');
},
error: function(data) {console.log('error');
console.log(data);
}
});
你好,以上是我的代碼,請告訴我所missed.I'm試圖從我的本地服務器做一個簡單的PSTrequest這個請求需要爲了Authorization頭正常運行。我已經執行POST請求並在Postman中成功檢索到數據,Ajax導致「無效的HTTP狀態碼302」錯誤,並且我的錯誤是XMLHttpRequest無法加載.....預檢的響應無效(重定向)上郵遞員工作正常,在AJAX不工作
仍顯示爲「SRATUS CODE:302」 – Pandi