I am creating a list using REST APIs. In my JavaScript code I have written something like this:
// If I declare 'waitDialog' then it is not get closed by
// calling 'waitDialog.close()'. Without any declaration it works.
var waitDialog;
function createList() {
// Show wait dialog
waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose("Please wait...", "Please wait...", 100, 300);
jQuery.ajax({
// List data
},
success: doSuccess,
error: doError
});
}
function doSuccess(data) {
waitDialog.close(); // Close wait dialog
}
function doError(data, errorCode, errorMessage) {
waitDialog.close(); // Close wait dialog
}
If I declare waitDialog
with statement var waitDialog;
then it does not work by calling waitDialog.close()
. Without any declaration it works and the dialog is closed. I found this question which elaborates on the difference between using var
, but nothing which would clarify this case.
Any idea why does it work without declaration and not with declaration?