2016-12-16 961 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