Home > Software design >  Bootstrap Modal doesnt open until function is finished
Bootstrap Modal doesnt open until function is finished

Time:08-05

I need the modal to open and then the for function to run but the modal won't open until the function is closed.


$("#myButton").bind('click', function () { 
 

var selectedRows = $("#jqxgrid").jqxGrid('getselectedrowindexes'); 
if(selectedRows>0){

var tableStr = "some html codes";

  for(){somecode}

$('#myModalBody').html(tableStr);
$("#myModal").modal('show');


 }

  

for (var a in selectedRows){

//some ajaxcodes look like
var jsonreq = new Object();
                      
    jsonreq.params = new Array();
    jsonreq.params[0] ="a";
    jsonreq.params[1] ="" b;
    jsonreq.params[2] ="";
                      
    sendAjax(jsonreq);
//some ajaxcodes like
}

});

$("#myModal").modal('show') line of code works but window opens at end of button function.

I need the modal to open and then the for function to run so we can see the changes

CodePudding user response:

I find it. I had to use ajax synchronously, but modals are asynchronous by their nature. Modal didn't open or change until ajax ends. So I made the ajax function asynchronous and forced it to run as if it were synchronous.

  • Related