【问题标题】:Works fine on postman and not working on AJAX在邮递员上工作正常,而不是在 AJAX 上工作
【发布时间】: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


    【解决方案1】:

    Why my $.ajax showing "preflight is invalid redirect error"? 可能的答案检查链接。

    我认为您有可能的解决方案尝试传递标头或将 http 更改为 https。请参考链接以获得更好的解决方案。

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 2015-07-12
      • 2021-05-22
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 2017-03-10
      相关资源
      最近更新 更多