XMLHttpRequest“加载资源失败"使用 Safari [英] XMLHttpRequest "Failed to load resource" with Safari

查看:130
本文介绍了XMLHttpRequest“加载资源失败"使用 Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从微控制器获取带有 XMLHttpRequest 的数据字符串.该请求适用于 Internet Explorer、Firefox、Chrome 和 Opera,浏览器控制台中没有任何错误.只有 Safari 会出现错误无法加载资源:网络连接丢失"的问题.微控制器仅使用数据字符串(5 个字节)进行响应.

I try to get a data string with a XMLHttpRequest from a microcontroller. The request works with Internet Explorer, Firefox, Chrome and Opera without any Errors in the Browser Konsole. Only Safari makes problems with the ERROR "Failed to load resource: The network connection was lost." The microcontroller answers only with the data sting (5 Bytes).

function httpGetFreq(){
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
            freq = parseFloat(xmlHttp.responseText) / 1000;
            animate ();
        }
    }
    xmlHttp.overrideMimeType('text/plain');
    xmlHttp.open("GET", "frequenz", true);
    xmlHttp.send(null);
}

推荐答案

可能还有一种可能发生这种情况.Safari 以外的浏览器会忽略响应类型,例如,如果您发出 HTTP 请求并且响应是 TCP 数据包.在这种情况下,Safari 会丢弃它,而 Chrome 等其他浏览器将其视为 HTTP 响应.

There could be one more possibility for this to happen. Browsers other than Safari ignore the response type, for example if you made a HTTP request and the response is a TCP packet. In this case Safari discards it, whereas other browsers like Chrome consider it as a HTTP response.

因此,请检查您的 HTTP 服务器代码,响应是否具有指向它的 HTTP 标头.在我看来,这一定是最可能的原因.在Wireshark中查看响应包类型是HTTP还是TCP.

So check in your HTTP server code whether response has a HTTP header to it. From my view that must be the most probable reason for this. Check in Wireshark the response packet type whether it is HTTP or TCP.

这篇关于XMLHttpRequest“加载资源失败"使用 Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆