2016-12-16 951 views
0

角度websocket插件正在浏览器中工作。但在移动设备生成apk之后,它不能正常工作,它显示错误。科尔多瓦websocket插件也无法正常工作,它显示错误代码1006.任何人都可以帮助我。我是新来的离子。cordova websocket插件显示错误代码1006和角度websocket插件显示isTrusted true错误

document.addEventListener('deviceready', function() { 
var ws = new WebSocket('ws://197.164.1.12:8080/example/2'); 

ws.onopen = function() { 
    alert('open'); 
    this.send('hello');  
}; 

ws.onmessage = function (event) { 
    alert(event.data); 
    this.close(); 
}; 

ws.onerror = function (event) { 
    alert('error occurred!'+JSON.stringify(event)); 
}; 

ws.onclose = function (event) { 
    alert('onclose code=' + event.code); 
}; 
ws.close = function (event) { 
    alert('close code=' + JSON.stringify(event)); 
    alert('onclose code=' + event.code); 
}; 
}, false); 
+0

你可以发布错误内容 –

回答

0

您的浏览器不允许CORS原始api访问。所以你可以添加插件 CORS Plugin for chrome

+0

在浏览器中工作正常。在移动它不工作 – Parimala

+0

检查下面的代码行可在config.xml Sathiyaraj

+0

是的,我也试过这个,但没有用 – Parimala