I think that all is in the title. When I started this I thought it will be a 5 minutes codes or a quick result when googling... But It's now three hours I'm on this:
Just show a dialog, with a "Please Wait..." message, while I'm performing an ajax call to retrieve some json result, and then show a "Result complete".
$('#switchOff').live("click",function(){
$('#dialog').dialog({
modal:true,
open: function(){
// I would like to call myAjax function
//From here ?
// While my dialog is showing the Wait message...
},
complete: function(){
//close the dialog when fished
$('#dialog').dialog('close');
},
});
});
function ajaxCall() {
//my ajax call
}
You should not use live
anymore. Use .on
instead. You are mixing up the dialog an ajax code. Here is an example of how I would do it.
Here is link to fiddle for demonstation
$('#switchOff').on("click", ajaxCall);
$("#loading").dialog({
hide: 'slide',
show: 'slide',
autoOpen: false
});
function ajaxCall() {
$.ajax({
url: '/echo/html/',
data: { html: '<p>JSON result</p>' , delay: 3},
method: 'post',
beforeSend: function(){
$("#loading").dialog('open').html("<p>Please Wait...</p>");
},
success: function(data) {
$('#loading').html("<p>Result Complete...</p>");
$('#ajaxResult').html(data);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With