سؤال

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