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
        {

        }
    });
});
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top