user1292656
user1292656

Reputation: 2560

jQuery close dialog when ajax call end

I have a function that inside makes an ajax call. At first I open the dialog with the message 'Loading' inside. Can i access the dialog again after the call and close it ?. Below is my code:

   function CallAction(){
    $("#example").dialog({modal: true});
    //do some ajax call
    //how to close it after call ends ?

Thanks in advance

Upvotes: 0

Views: 798

Answers (3)

Gurminder Singh
Gurminder Singh

Reputation: 1755

if you want to close the dialog in any case(success or error), use complete:

complete: function() {
   $("#example").dialog({modal: true});
}

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Use the complete callback of the ajax request, then use the close method to close the dialog

$.ajax({....}).always(function(){
    $("#example").dialog('close');
})

Upvotes: 1

tymeJV
tymeJV

Reputation: 104775

Yes, close it in the AJAX success or done call:

success: function(data) {
    //do stuff
    $("#example").dialog('close');
}

Upvotes: 3

Related Questions