vendredi 6 janvier 2017

Redirect on AJAX request

I generally have the following common code to make AJAX requests in my app;

doXhr: function(postData, requestUrl){  
    var promise = new Ember.RSVP.Promise(function(resolve, reject) {        
        return $.ajax({
            url: requestUrl,

        })
        .done(function(response, status, xhrObject) {         
          resolve(response);
        })
        .fail(function(xhrObject, status, error){           
            reject(errorObj);
        });
    })  
    return promise;
},

I invoke this as below

postToExternal: function(args, url) {
        var deferred =  this.doXhr(args,url);
        return deferred;        
    }

For one of the requirements, I need to make a POST AJAX request & the server wold then redirect (302) to some other URL

So my question is would the above way of calling doXhr() still work i.e. returning deferred

OR since I know it is going to be a redirect, I should just use $.ajax() and leave (as there is no use of waiting for the promise to be resolved)




Aucun commentaire:

Enregistrer un commentaire