I'm getting some strange behaviour when using the parseInt().
webSocket.onmessage = function (event) {
    var raw = event.data;
    alert(raw);
    var data = raw.split(":");
    alert("lat:\"" + data[0] + "\" lon:\"" + data[1] + "\"");
    var x = parseInt(data[0]);
    var y = parseInt(data[1]);
    alert("lat:" + x + " lon:" + y);
}
The first alert outputs: 100:100 - this is the string sent from the server.
The second alert outputs: lat:"100" lon:"100" - which is fine
However, the third alert outputs: lat:1 lon:NaN
What could cause this?
UPDATE:
The problem was the encoding on the server side generating some invisible unwanted characters. I updated the server code and the problem was gone. Working solution.
 
     
     
    