Javascript XMLHttpRequestonReadyStateChange不';我不能在firefox上工作
我正在开发一个web界面来配置和监控我们的设备。为了进行监控,我正在使用当用户成功连接并在web会话结束时关闭时创建的XMLHttpRequest对象。我们设备的软件通过创建的异步通道报告有关设备状态的信息。 在Firefox(67.0.2)上,在旧版本(33.1)上永远不会调用回调。 你知道这种行为吗 谢谢Javascript XMLHttpRequestonReadyStateChange不';我不能在firefox上工作,javascript,jquery,json,Javascript,Jquery,Json,我正在开发一个web界面来配置和监控我们的设备。为了进行监控,我正在使用当用户成功连接并在web会话结束时关闭时创建的XMLHttpRequest对象。我们设备的软件通过创建的异步通道报告有关设备状态的信息。 在Firefox(67.0.2)上,在旧版本(33.1)上永远不会调用回调。 你知道这种行为吗 谢谢 在发送请求之前尝试设置它。首先是onreadystatechange=…然后是send(…)谢谢Florent,但结果是一样的。奇怪的是,我在FF 68上尝试了你的代码(使用不同的请求ip
在发送请求之前尝试设置它。首先是
onreadystatechange=…
然后是send(…)
谢谢Florent,但结果是一样的。奇怪的是,我在FF 68上尝试了你的代码(使用不同的请求ip),效果很好。您确定update.html
与您的客户端在同一台服务器上,您没有任何跨源请求
错误吗?还有一个愚蠢的问题,但以防万一,您确定要随时调用openAsynchChannel()
函数吗?
function openAsynchChannel(){
if (window.XMLHttpRequest) {
// Native support of XMLHttpRequest
Communication_asynchChannel = new XMLHttpRequest();
}
else {
// code for IE6, IE5
Communication_asynchChannel = new ActiveXObject("Microsoft.XMLHTTP");
}
Communication_asynchChannel.open("POST", "update.html", true);
Communication_asynchChannel.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Communication_asynchChannel.setRequestHeader("Accept", "text/html");
Communication_asynchChannel.timeout = 0;
Communication_asynchChannel.overrideMimeType("text/plain");
Communication_asynchChannel.setRequestHeader("X-Requested-With", "XMLHttpRequest");
Communication_asynchChannel.send("CMD_TYPE=1|&PARAMETER1=" + navigator.appCodeName + "_" + (new Date()).getMinutes() + "\r\n");
// Hook the callback
Communication_asynchChannel.onreadystatechange = Communication_receiveAsync;
}
function Communication_receiveAsync(){
console.log(Communication_asynchChannel.responseText);
}