XMLHttpRequest onReadyStateChange在Firefox上不起作用

时间:2019-08-30 12:28:59

标签: javascript jquery json

我正在使用网络界面来配置和监视我们的设备。为了监视,我使用在用户成功连接并在Web会话结束时关闭时创建的XMLHttpRequest对象。我们设备的软件会通过创建的异步渠道报告有关设备状态的信息。 在Firefox(67.0.2)上,从不调用回调,而是在旧版本(33.1)上起作用。 这种行为的任何想法 谢谢

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);
}

0 个答案:

没有答案