iOS Firefox XMLHttpRequest 错误响应

iOS Firefox XMLHttpRequest wrong response

我有一个函数可以发送 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);
      } 
});

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

有些浏览器对 headers 非常挑剔。您试过发送基本授权吗?包括用户名和密码..

例)

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

试试看吧:)