0

This question already has an answer here:


I am using SP.RequestExecutor to add attachments to a list item.
I followed Can't upload a non-text file to SharePoint App via REST API
I need to wait the completation of the asynch call of executeAsync method.
How can I achieve this?

Thanks,Nk

marked as duplicate by Arsalan Adam Khatri, SPArchaeologist, Eric Alexander Apr 2 '14 at 21:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I tried to use $.when and then .done() but seems that the executeAsync method does not return a Deferred or Promise obj – Nk SP Apr 2 '14 at 14:26
0

You can use a deferred with a resolve for your return value that is populated during async execution. After that you return a promise that you catch in a done method on function calling (check jQuery documentation: http://api.jquery.com/deferred.promise/):

functionToCall().done(function (returnedValue) {
    // do something with the returned value
});

function functionToCall() {

    var dfd = $.Deferred(function () {

        var valueToReturn = clientContext.get_web();

        clientContext.load(valueToReturn);

        clientContext.executeQueryAsync(
            function () {
                dfd.resolve(valueToReturn);
            },
            function (sender, args) {
                //throw an error
            });
    });

    return dfd.promise();
}
  • I need to use it inside a reader.onload and is seems hava some problems – Nk SP Apr 2 '14 at 14:52

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