10

I'm trying to use the SharePoint 2013 "Working on it..." during ajax call. This is the code:

function ShowWaitDialog() {
    SP.UI.ModalDialog.showWaitScreenWithNoClose(SP.Res.dialogLoading15);
}

function BuildTable() {
    ExecuteOrDelayUntilScriptLoaded(ShowWaitDialog, "sp.js");

    //Do something

    SP.UI.ModalDialog.close();
};    

The animation loads but never closes becouse on SP.UI.ModalDialog.close() I get the error "Object doesn't support property or method 'close'".

But on https://msdn.microsoft.com/en-us/library/office/ff410259(v=office.14).aspx I see that the close method exists.

Some suggestions? Thank you

6

You call your method showWaitScreenWithNoClose using asyncronously with callback ExecuteOrDelayUntilScriptLoaded. If sp.js is not loaded, then closing event can fire before the wait dialog is showed.

Your code should look like this:

var waitDialog = null;

function BuildTable() {
    ExecuteOrDelayUntilScriptLoaded(function() {
        waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose(SP.Res.dialogLoading15);

        // DO SOMETHING;
        DoSomeWorkUsingAjax(myCallBack)


    }, sp.js);
}

function myCallBack() {
    if (!fIsNullOrUndefined(waitDialog)) {
        waitDialog.close(SP.UI.DialogResult.OK);
        //or SP.UI.ModalDialog.close();
    }
}
  • Hello, in my situation in the DO SOMETHING part I've to call something like $.when(ajax1(), ajax2()).done(function() { CallAfterAjax(); });. In this situation where I've to call myCallBack method? Thank you – Yiyi Chen Sep 23 '15 at 13:35
  • Try this `$.when(....).done(myCallBack); – ECM4D Sep 23 '15 at 14:05
  • Hello, I tried as you suggested but it didn't works. I debugged it with IE Developer Tools and Firebug putting a breakpoint inside myCallBack and it never has been called. Does it means that my Ajax call don't end? – Yiyi Chen Sep 23 '15 at 14:47
  • I put function () { alert('Hello World'); } inside .done() and it shows. – Yiyi Chen Sep 23 '15 at 14:50
  • Then try function () { myCallBack(); alert('Hello World'); } – ECM4D Sep 23 '15 at 18:51
10

You need to call close() on object returned from showWaitScreenWithNoClose(). This works for me:

var loading = SP.UI.ModalDialog.showWaitScreenWithNoClose(SP.Res.dialogLoading15);
loading.close();
  • Hello I already tried it, I get the same error "Object doesn't support property or method 'close'". – Yiyi Chen Sep 23 '15 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.