That came out really well. Any ideas on how to detect user inactivity and stop this ajax call?
There is no real way to detect this, you can maybe monitor the window blur. You can also look at onmousemove and other events such as keypress.
And one more doubt,what happens if the server doesn't respond back in 5 secs?
You can either abort the request. Most people will not use intervals, they use setTimeouts. You fire the setTimeout after you get the response back. You are using setTimeout, so looks to be fine with me.
Eric