I am making ajax request to a particular server and getting the response also. I am doing cross domain request so using jsonp. Is there a way to get the server time to which i am making the request. Will it be better to write php script or doing just ajax request is good. Suppose if i make the following request :
$.ajax({
dataType: 'jsonp',
data: 'jsonp=date',
jsonp: 'jsonp_callback',
url: 'http://www.google.com',
success: function (data) {
}
});
How can i get the server time from this request? Please help if any suggestion. Also after getting the time if i use setInterval method to update time every second will it be a costly operation or better to make the same ajax request after a particular time to update time. I have real time data to update with the time.
You can’t get the server’s time if it doesn’t explicitly provide it to you.
You can read its HTTP headers, but that’s not a good thing since the headers may not provide this information every time, or their format may not be the same all the time.
Also, I don’t see the point of asking it every second.
Ask it one single time, calculate the difference between its time and yours, and here you go: you got the difference of time and you can use it wherever you want.
Keep in mind that even if you get the time, there probably will be a difference between the one you got and the server’s real time because of the network’s latency.