【问题标题】:iOS Firefox XMLHttpRequest wrong responseiOS Firefox XMLHttpRequest 错误响应
【发布时间】:2016-05-17 21:27:47
【问题描述】:

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

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

【问题讨论】:

  • jQuery 版本是否存在特定问题?您是否检查过控制台是否有错误?您还应该删除 crossDomain、username 和 password 属性。
  • 我在控制台中没有看到任何错误,最初我只有 url、accepts、error 和 success 属性,这没有任何区别。
  • 那您能描述一下您所说的“错误响应”是什么意思吗?
  • handler 被调用了吗?
  • @rory,我无法看到设备上的响应,因为我不知道在 Firefox 中检查手机网络的方法。但是如果认证成功,桌面响应总是 JSON 响应,如果登录成功,我会得到一个 HTML 页面作为响应,也就是后端的内部登录页面。

标签: javascript jquery ios firefox xmlhttprequest


【解决方案1】:

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

例如)

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

试试看吧:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多