tags:

views:

53

answers:

3

I am trying to get the data from the php file and update every second so when the information changes in the php file it will auto update

 $(document).ready(function() { 
$.ajaxSetup ({
    cache: false
});
 $("#hidden").hide(); 
 $("#textfield").val(""); 
 $("#textarea").val(""); 

 var hol=$(this).attr('myval'); 
 var formContent ="action=getlink&link="+hol; 

 $.getJSON("inc/json.php",formContent, function(json){ 
 $("#textfield").val(json.name); 
 $("#textarea").val(json.desc); 
 $("#formHeader").text("Edit"); 
 $("#ajaxBox").text("All info loaded OK"); 
 });


 });
+3  A: 

Put that code in a function and call setTimeout()

Byron Whitlock
+1 for understanding the title.
Jason Rowe
+4  A: 

Use setInterval(), not setTimeout(). setInterval will call the function at your specified interval.

var interval = setInterval(function() { 
    /* do something that will execute every 1000 milliseconds*/ 
}, 1000);
uhleeka
A: 

This will call when it receives a response or an error and retry. Possibly a more elegant solution than checking every second.

function foo()
{   
 $.ajax({
        type: "GET",
        url: ,
        data: ,
        timeout:50000, /* Timeout in ms */

        success: function(data){ /* called when request completes */
                'foo()', /* Request next message */
            );
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            setTimeout(
                'foo()', /* Try again after.. */
                "15000"); /* milliseconds (1second) */
        },
    });
}
Gazler