0

How to refresh or update my content through jquery ajax when ever server changes the code?

Remember:-

  1. Take this stackoverflow page as example of what i am looking for. It updates its content with out clicking anywhere, With out any timeout or time interval functions. So like this page i am looking for.
  2. I am working on cordova, so that i can get access from server only via jquery ajax. So how to invoke JS functions from server or only if server content changes?
Vicky
  • 469
  • 3
  • 9
  • 22

1 Answers1

3

There are two ways you can do.

  1. Web Sockets. Using the HTTP 101 Switching Protocols, you can have a persistent connection to the server and work out on the changes to the view.
  2. Long Polling. If your server is hard enough for no DDoS attacks, you can use this method to continuously ping the server, and get the latest info.

Does the above two methods help? There are other articles that help you in differentiating Web Sockets and Long Polling:

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
  • sorry for my incomplete question i asked before. Please look at my edit now – Vicky Jul 06 '15 at 10:27
  • cordova framework works with html, JS and css. Not like native mobile applications. so accessing device features are restricted in cordova framework. so what you have explained in your answer can be useful for web page. from cordova, i am using ajax to get api from server and i am populatinf it in HTML. So how can i invoke ajax functions from server? – Vicky Jul 06 '15 at 10:35
  • @Vicky You need to use WebSockets in Cordova. https://github.com/knowledgecode/WebSocket-for-Android – Praveen Kumar Purushothaman Jul 06 '15 at 10:37
  • 1
    yeah got it. Thank you – Vicky Jul 06 '15 at 10:40