jQuery dialog box not closing till a function is executed -


i'm using jquery dialog box alert user deleting record in table. following code:

$('#deletebutton').click(function () {     if($(this).attr('disabled')=='disabled'){         //do nothing     }     else{         var isdeleteyes = false;         $('#delete-confirm').dialog({                     height : 150,                     width : 400,                     autoopen : true,                     close: function( event, ui ) {                         //alert(closed)                     },                     buttons : {                         "yes" : function () {                             isdeleteyes = true;                             $(this).dialog("close");                             deletefunction();                          },                         "no" : function () {                                     isdeleteyes=false;                                     $(this).dialog("close");                                 }                     },                     title : "confirm delete",                     resizable : false,                     modal : true,                     overlay : {                         opacity : 0.5,                         background : "black"                     }                 });       }  });  function deletefunction(){    /*     *     * logic delete     *     */   } 

the problem that, in yes button i'm closing the dialog before function call deletefunction(). not closing until function completed execution. alert in close function appearing click yes or no. dialog not getting closed in ui.

from description, because running synchronous operation in deletefunction, (which means 1 script run after one, if asynchronous means run parallel).

$(this).dialog("close"); script update dom hide element, hide element view browser repaint has happen.

in browser both javascript , repaint/reflow functions runs in same thread (but synchronous) mean 1 run after previous script completed action, though dialog marked hide not hidden view unless current script execution over, , browser gets chance execute re-flow.

one solution short cut problem use timeout, if want execute delete function in async mode below

"yes": function () {     isdeleteyes = true;     $(this).dialog("close");     settimeout(deletefunction, 1);  }, 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -