Question

What is the event to do actions while $.post method is in progress jQuery.

Explained more clearly: I use $.post method in my code in PHP. I need to display loading image until the $.post returns a value!

My code

$("#wit").click(function(){
    var story = $("#story").val();
    $.post('diary/ajax/ajax.php', {newdiary:story},function(data){
        if(data=="SORRY")
        {
            alert("Sorry! Try Again in few seconds");
        }
        else
        {

        }
    });
});
Était-ce utile?

La solution

Just display the loading image in the line before you make your post() call. Then hide the loading image in the callback function. Note for this sort of operation you should also have a callback for a failed call so that you can hide the image in case the call fails for some reason.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top