jQuery getJSON with timeout

function testAjax() {
        var params = "test=123";
        var isneedtoKillAjax = true; // set this true

        // Fire the checkajaxkill method after 10 seonds
        setTimeout(function() {
            checkajaxkill();
        }, 10000); // 10 seconds                

        // For testing purpose set the sleep for 12 seconds in php page 

        var myAjaxCall = jQuery.getJSON('index2.php', params, function(data, textStatus){               
            isneedtoKillAjax = false; // set to false
            // Do your actions based on result (data OR textStatus)
        }); 

        function checkajaxkill(){

            // Check isneedtoKillAjax is true or false, 
            // if true abort the getJsonRequest

            if(isneedtoKillAjax){
                myAjaxCall.abort();
                alert('killing the ajax call');                 
            }else{
                alert('no need to kill ajax');
            }
        }
}

Hear is my post
http://stackoverflow.com/questions/4138470/jquery-getjson-with-timeout/9823889#9823889

Comments

Popular posts from this blog

AIOMgr: Preparing flush failed with VERR_NOT_SUPPORTED, disabling async flushes

Create Virtual Host in IIS Server

The model type is invalid. please select an item from the list ( ASP.Net MVC)