문제

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