Return to Snippet

Revision: 41290
at February 15, 2011 15:26 by Sullan


Initial Code
var pendingCall = { timeStamp: null, procID: null };

$('li a').click(function (e) {
    e.preventDefault();
    var getUrl = $(this).attr("href");
	var timeStamp = Date.now();

    var printCall = function () {
        $.ajax({
            url: getUrl,
            type: "GET",
            beforeSend: function () { },
            error: function (request) { alert(request) },
            success: function (data) {
                if (pendingCall.timeStamp != timeStamp) { return false; }
                $('#graphContent').html(data);
                pendingCall.procID = null;
            }
        });
    };

    if (pendingCall.procID) {
        clearTimeout(pendingCall.procID)
    };
    pendingCall = { timeStamp: timeStamp, procID: setTimeout(printCall, 3000) };
});

Initial URL

                                

Initial Description

                                

Initial Title
AJAX Delay for X seconds

Initial Tags
ajax

Initial Language
jQuery