weixin_33725270 2017-01-06 13:58 采纳率: 0%
浏览 46

根据AJAX请求重定向

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)

  • 写回答

0条回答 默认 最新

    报告相同问题?