2

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?

Community
  • 1
  • 1
Naveen
  • 6,786
  • 10
  • 37
  • 85

2 Answers2

3

I could not recreate your declaration issue. One thing I noticed... I believe you need to pass the SP.UI.DialogResult enumerable to the close method

waitDialog.close(SP.UI.DialogResult.OK);
Brandon Runyon
  • 231
  • 1
  • 4
  • 14
0

//show and hide waiting on it javascript

function waitMessage() {
    window.parent.eval("window.waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Processing...', '', 90, 300);");
}

function closeMessage() {
    if (window.frameElement != null) {
        if (window.parent.waitDialog != null) {
            window.parent.waitDialog.close();
        }
    }
}
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60