I got a webapp that i am calling a webservice, im saving the data from the webservice on my database, and every time i save i am checking if the ID exists or not, if exists do not save and if dosent exist save. The problem i am facing now its the problem that i want to do this action every 5 seconds on all the pages. So i try to write the code on the layout page, but that slows a lot my webapp. so i thought i will right it on a controller and write a ajax call that calls that controller every 5 seconds, the problem with that is that wen the layout opens it will call the function but the user will go immediately to one of the pages so will start again from the beginning the ajax. Any idea how can i solve it? Thank you.
Asked
Active
Viewed 53 times
-2
-
1Your post is very hard to read due to the lack of proper paragraphs, grammar and use of capital letters. – mjwills Sep 14 '17 at 10:16
-
You should opt for `Long polling` or `Web-sockets`. Check out this [link](https://stackoverflow.com/questions/14051795/push-changes-to-a-webpage-without-refreshing) – Abdul Samad Sep 14 '17 at 10:52
-
Example of Long Polling `(function myFunction() { $.ajax({ url: 'some url', success: function(data) { // use the data provided over API }, error: function(err) { // Handle error }, complete: function() { // Schedule the next request when the current one's complete setTimeout(myFunction, 5000); } }); })();` – Abdul Samad Sep 14 '17 at 10:59