iOS Firefox XMLHttpRequest 错误响应

iOS Firefox XMLHttpRequest wrong response

本文关键字:响应 错误 XMLHttpRequest Firefox iOS      更新时间:2023-09-26

我有一个函数,它发送XMLHttpRequest GET从我的后端检索JSON。

xhttp.onreadystatechange = function()
{
    if(xhttp.readyState == 4 && xhttp.status == 200)
    {
        applicationUtil.showLoader(false);
        if(handler != null)
        {
            alert(xhttp.responseText);
            if(xhttp.responseText != "" && this.getResponseHeader('content-type') == "application/json")
            {
                handler(JSON.parse(xhttp.responseText), false);
            }
            else
            {
                handler("", true);
            }
        }
    }
}
xhttp.open("GET", "../../csp/healthshare/hsanalytics/Custom.AMY.REST.Session.cls?CacheUserName="+ username +"&CachePassword="+ password, true);
xhttp.send(null);

现在,此功能在任何设备上的任何浏览器上100%有效,接受iOS Firefox。我试过走jQuery路线,结果相同:

$.ajax({
      url: "../../csp/healthshare/hsanalytics/Custom.AMY.REST.Session.cls?CacheUserName="+ username +"&CachePassword="+ password,
      accepts:"application/json",
      cache: false,
      crossDomain: true,
      dataType: "json",
      username: username,
      password: password,
      error: function(event)
      {
          handler("", true);
      },
      success: function(data, status)
      {
          handler(data, false);
      } 
});

花了几个小时研究这个主题,但我无法找到任何针对我的问题的文章。

有些浏览器在标题方面非常挑剔。您是否尝试过发送基本授权?包括用户名和密码。

例如)

{
"Authorization": "Basic " + btoa(username + ":" + password)
},

一试,看看:)