cordova - Bootstrap Modal not loading immediately on click button due to jQuery ajax call -
i using bootstrap modal show loading message when doing ajax call validating url based on value returned statuscode. user clicks button loader message should displayed , in behind jquery ajax call made.
bootstrap modal displayed slight delay instead want show bootstrap modal loader message.
am using bootstrap, backbone, jquery. hybrid mobile app developed using web technologies.
here doing,
bootstrap modal code, hidden (i opening modal via javascript)
<div class="modal fade bs-example-modal-lg" id="mymodal" tabindex="-1" aria-hidden="true" data-backdrop="static" role="dialog"> <div class="vertical-alignment-helper"> <div class="modal-dialog modal-lg vertical-align-center"> <div class="modal-content"> <div class="modal-body"> <div id="gifload"><img id="loading-image" src="img/ajax-loader.gif" alt="loading..." /> </div><div id="dataload"><p>please wait..!!!</p></div> </div> </div> </div> </div> </div>
the button click event triggered via backbone
openpage: function () { $('.modal').modal('show'); // opening bootstrap model on button click var networkstate = navigator.connection.type; if (networkstate === connection.none) { // check phone has internet connection or not proceed further. var loaderview = safetyloaderview(); loaderview.render(); loaderview.appendmessage('internet connection seems offline'); loaderview.show(); } else { var textvalue = $('#inputvalue').val(); // entered value of input box if (textvalue === null || textvalue === "") { $('.modal').modal('hide'); // if input box empty change color of border of thr input box. this.$el.find('#inputtext').addclass('has-error'); } else { var serverurl = "https://www."+ value1 + value2 + "google.com"; // forming url based on values entered user. var status = this.validateurl(serverurl); // calling validateurl method validate url. if (status === 200) { $('.modal').modal('hide'); // if status code equal 200 opening next screen of application var url = "page2.html"; window.location = url; } else if (status === -1) { $('.modal').modal('hide'); var loaderview = new safetyloaderview(); // handling status code other 200,400,404 , 500. loaderview.render(); // displaying standard message remaining status code. loaderview.appendmessage('the request not completed'); loaderview.show(); } } } },
validating url method part of backbone view:
validateurl: function (url) { var stat = -1; // validating url. based on status code returned, appropriate error message displayed. // new status code can added handle message. //------------------------------------------------------------------------ // ----------- feel due ajax call done here giving me delay load modal // instead want instanly, if use alert box displayed //------------------------------------------------------------------ $.ajax(url, { async: false, statuscode: { 200: function (response) { stat = 200; }, 400: function (response) { $('.modal').modal('hide'); // hiding modal var loaderview = new safetyloaderview(); loaderview.render(); loaderview.appendmessage('the request not understood'); loaderview.show(); stat = 400; }, 404: function (response) { $('.modal').modal('hide'); // hiding modal var loaderview = new safetyloaderview(); loaderview.render(); loaderview.appendmessage('requested url not found'); loaderview.show(); stat = 404; }, 500: function (response) { $('.modal').modal('hide'); // hiding modal var loaderview = new safetyloaderview(); loaderview.render(); loaderview.appendmessage('internal server error'); loaderview.show(); stat = 201; }, }, }); return stat; },
if wont call validateurl method, bootstrap modal loads instantly.
my question how show loader modal during ajax call.?
Comments
Post a Comment