javascript - How to point a WebSocket to the current server -
i have jetty 8 server running (hopefully websockets).
if want send data server ajax call, can this:
$.ajax({ url: "ajax?a=getsomedata" }); in scenario, if connect server @ 192.168.1.100, real url data from, 192.168.1.100/ajax?a=getsomedata, if connect server running same software @ 192.168.1.200, url 192.168.1.200/ajax?a=getsomedata.
but if want accomplish same thing using websockets, cannot find how it:
var socket = new websocket('ws://www.example.com/'); works. want relative url:
var socket = new websocket('ws://sockets?a=getsomedata'); so - ajax request - if connecting server @ 192.168.1.100, url 192.168.1.100/sockets?a=getsomedata, , if connect 192.168.1.200, url 192.168.1.200/sockets?a=getsomedata.
how can accomplish this?
just build url yourself:
var socket = new websocket("ws://" + location.host + "/whatever"); the "location" object property of "window" object, , therefore globally available.
Comments
Post a Comment