使用WebSocket的时候报错,代码:
var ws = new WebSocket("ws://dev.ectrend.com:80");
ws.onopen = function() {
};
ws.onmessage = function(e) {
// Receives a message.
var respObj = JSON.parse(e.data);
console.log(respObj);
initTipsInfo(respObj);
};
/**
* 根据返回的通知提示信息,初始化对应的dom元素
* @param respObj
*/
function initTipsInfo(respObj){
if(parseInt(respObj.msg_cnt) === 0){
$("#m-info-count").hide();
}else {
$("#m-info-count").show();
$("#m-info-count").html(respObj.msg_cnt);
}
if(parseInt(respObj.logistics_msg_cnt) === 0){
$("#wuliu-count").hide();
}else {
$("#wuliu-count").show();
$("#wuliu-count").html(respObj.logistics_msg_cnt);
}
if(parseInt(respObj.sys_msg_cnt) === 0){
$("#sys_count").hide();
$("#mine-tip-count").hide();
}else{
$("#sys_count").show();
$("#mine-tip-count").show();
$("#sys_count").html(respObj.sys_msg_cnt);
$("#mine-tip-count").html(respObj.sys_msg_cnt);
}
};
ws.onclose = function() {
ws.close();
};
ws.onerror = function (evt) {
console.log("连接出错了!");
};
报错信息:
WebSocket connection to 'ws://dev.ectrend.com/' failed: Error during WebSocket handshake: Unexpected response code: 200
后台的问题,已搞定