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?


  • 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

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


            function () {
            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.