Polling the state of servers from the script from an on-demand script is usually going to be a very bad idea. Where there is high demand for your script you will be endlessly probing the servers (we'll come back to 'ping' later) which is very inefficient at best and could easily be exploited to launch a reflected denial of service attack against the server. Regardless of the traffic volume, response times will be very slow as each instance polls each server. If a server is unavailable then the situation becomes much worse as you need to wait for a timeout to determine its status (browser use adaptive timeouts for this rather than the OS default).
A better solution is to scheduled probes for checking the status - this is how tools like BMC Patrol and Nagios work for service monitoring.
Regarding the method of polling the service, while its usually true that if you can't ping a node, then you won't be able to access the services it should be providing, that does not mean that if you can ping a server you can access its services. Carrying out a TCP handshake on the service socket will give a much more accurate description of whether the service is available. However if you are repeatedly connecting to someone else's server without exchanging any data, this might be perceived as a denial of service attack by the admins and hence your IP will get black listed. i.e. you should probably be talking to whoever runs the servers (if it's not yourself).
Probing from javacript is only going to work if the server is talking HTTP. It is possible to infer the state of a port from the time it takes for an error to come back (have a google for 'portscan javascript' for some examples) but again the results will not be definitive unless you know how the network and servers are configured.