-2

I need Ajax script that will check every 5 seconds, the contents of file.php

file.php may contain only true or false.

If true - script must perform an action. if false - script should continue to check the file for true

how to make it?

Reporter
  • 3,897
  • 5
  • 33
  • 47
user1062240
  • 127
  • 1
  • 1
  • 9

3 Answers3

1

For a starting point ave a look at this -> http://api.jquery.com/jQuery.get/

Example: Gets the test.php page contents, which has been returned in json format (<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>), and adds it to the page.

 $.get("test.php",
   function(data){
     $('body').append( "Name: " + data.name ) // John
              .append( "Time: " + data.time ); //  2pm
   }, "json");

To repeat something every # seconds have a look at the setInterval function :

Calls a function repeatedly, with a fixed time delay between each call to that function.

Then when you have created some code - come back and post your issues

Manse
  • 37,765
  • 10
  • 83
  • 108
0

will this help?

Call js-function using JQuery timer

then use jquery ajax methods. http://api.jquery.com/jQuery.ajax/

I would help you more but you need to first help your self.

Community
  • 1
  • 1
Antony Delaney
  • 1,158
  • 4
  • 15
  • 39
  • If you have any problems post your code explaining whats not working and what you have tried. We will be more than happy to help. – Antony Delaney Dec 06 '11 at 11:52
0

You just need to perform regular $.ajax call inside setInterval. Maybe clearInterval would be useful too, if you want to stop checking remote file.

the_ghost
  • 101
  • 13