【发布时间】:2017-10-03 13:17:41
【问题描述】:
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);
}
});
嗨,上面是我的代码,请告诉我错过了什么。我正在尝试从我的本地服务器执行一个简单的 PSTrequest,这个请求需要一个 Authorization 标头才能正常运行。我已执行 POST 请求并在 Postman 中成功检索数据,Ajax 导致“无效 HTTP 状态代码 302”错误,我的错误是 XMLHttpRequest 无法加载.....预检响应无效(重定向)
【问题讨论】:
标签: php ajax rest api codeigniter