Search code examples
visual-studio-lightswitchlightswitch-2013

In JavaScript, how do I show screen progress indicator during an ajax call


JavaScript novice here.

I'm attempting to do something like this:

msls.showProgress($.ajax({
        url: "/Web/DataImport.ashx",
        type: "POST",
        contentType: false,
        processData: false,
        data: file
    }).then(
    function success(result) {
        // Do something
    },function error(err) {
        // Do something else
    })));

Basically, I want the LightSwitch indicator to display until the ajax call returns. However the above code doesn't work, because showProgress is expecting a WinJS.Promise object.

Anyone has an idea on how to to achieve the desired behavior?

Yours,


Solution

  • try this:

    msls.showProgress(msls.promiseOperation(function (operation) {  
       $.ajax({
        url: "/Web/DataImport.ashx",
        type: "POST",
        contentType: false,
        processData: false,
        data: file
        }).then(
          function success(result) {
          msls.showMessageBox(result);
          },
           function error(err) {
        operation.error(err);
         }))  
    })  
    );