jquery her sn güncellemek için nasıl

3 Cevap php

Ben php dosyasından veri almak ve php bilgileri değişirse dosya zaman yani her saniye güncellemek için çalışıyorum bu otomatik güncelleme olacak

 $(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 Cevap

SetInterval () kullanın, (setTimeout değil). setInterval belirlenen aralıklarla işlevini çağırır.

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

Bir işlevi bu kodu koyun ve setTimeout çağrı ()

Bir yanıt veya bir hata alır ve yeniden yaparken bu arayacak. Muhtemelen her saniye kontrol daha zarif bir çözüm.

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) */
        },
    });
}