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

152 views Asked by At

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,

1

There are 1 answers

1
farhadamjady On BEST ANSWER

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);
     }))  
})  
);