I need to check whether a cross-domain server is available or not. Choices are:
- sending ping
- getting a HEAD request
- making own server as proxy server and pass cross-domain server data in arguments
- making a JSONP request
- I want to do this in client side (I can always reach cross-domain server from my server).
- I need to know client's state. So javascript is mandatory.
- I don't want to use own server as proxy, because this can cause security problems and I can't know client's state.
- I tried JSONP below, but it is also OK to have a ping solution or any other solution that you can recommend.
- I don't have any privilege in cross-domain server. I can only make restful requests from server with api key.
- I prefer asynced, jquery based solutions. But it is ok to use pure javascript.
- The only thing I need is to check whether server is available or not. It would be better if I can know the response time from server. I don't need other data about server.
My fiddle is like this.
$.ajax({
url: "https://twitter.com",
dataType: 'jsonp',
success: function (data) {
console.log("success");
//console.log("data2:"+data);
//console.log("data:"+JSON.stringify(data));
},
error: function (r, s, e) {
console.log("error status: " + r.statusText + ", " + r.status);
console.log("error r: " + r);
console.log("error e: " + e);
}
});
When I try this code I get "Uncaught SyntaxError: Unexpected token < " error in first line of the response data. So consequent javascript codes doesn't work.
How can I check this availability ?