1

I have a php page and I want to use ajax or jquery to load a php page which is within the same file directory ever x minutes. the external php page I want to load every x minutes contains php code that queries a mysql database looking for new rows of data and if it finds one pops up a jquery module window with a form in it. My issue is all the same code I seem to find requires me to setup a div in the parent page and wants to load that content into just that div. However I want to display the external php page over the top of the entire page if that makes sense how I am explaining it.

My code I am trying to use but does not work is

setInterval(
  $.get( "checkapiinsert.php", function( data ) {
     $( "body" )
  },10000);
Jayreis
  • 253
  • 1
  • 7
  • 28
  • Basically I have a file that contains php and jquery and I want to keep reloading it every x number of minutes and display its result as if its part of the screen/file the user is currently on. – Jayreis Apr 16 '14 at 15:00
  • Duplicate of [http://stackoverflow.com/questions/4930439/call-jquery-ajax-request-each-x-minutes](http://stackoverflow.com/questions/4930439/call-jquery-ajax-request-each-x-minutes) – Matt The Ninja Apr 16 '14 at 15:01
  • Thanks but that shows me a code that looks similar to what I have above. So how would I get my above code which is similar to the url you posted to actually work. I am given the code I have been told show work and its now working so I am coming to this site to ask for help to fix my code since it looks correct but it not working. I believe its the $( "body") part that is incorrect any suggestions on how to correct it. Again I want to code from the external page to not load in a specific div. – Jayreis Apr 16 '14 at 15:07

2 Answers2

1

If you want to refresh the whole page every 10000 miliseconds, why not use a meta tag or use javascript for a refresh

<meta http-equiv="refresh" content="10">

Or use javascript

 setInterval(function(){location.reload(); },10000);
Daniel
  • 4,816
  • 3
  • 27
  • 31
1

You were pretty close with your code.

setInterval(function(){
    $.get('checkapiinsert.php', function( data ) { 
       $('body').html(data);
    });
}, 5 * 1000 * 60); 

Where 5 * 1000 (milliseconds) * 60 (seconds) = 5 minutes

Though a better solution would be:

<meta http-equiv="refresh" content="300;url=/checkapiinsert.php">

Assuming checkapiinsert.php is at your root.

Where 300 = 5 minutes

iambriansreed
  • 21,935
  • 6
  • 63
  • 79