【问题标题】:Modify ajax response that gets passed to .done()修改传递给 .done() 的 ajax 响应
【发布时间】:2018-05-06 16:37:28
【问题描述】:
this.getFullAddress(id).done(function(data) {
    // need to have both the response (data) and the id
});

getFullAddress(id) {
    var response = $.ajax({
        url: 'http://whatever.com'
    }); // modify this (add id)

    return response;
}

有谁知道如何做到这一点?

【问题讨论】:

    标签: ajax jquery-deferred


    【解决方案1】:

    好的,找到了:

    getFullAddress(id) {
        $.ajaxSetup({
            dataFilter: function (response) {
                response = JSON.parse(response);
                response['id'] = id;
                response = JSON.stringify(response);
    
                return response;
            }
        });
    
        return $.ajax({
            url: 'http://whatever.com'
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-21
      • 2014-06-07
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      相关资源
      最近更新 更多