weixin_33699914 2016-05-27 10:26 采纳率: 0%
浏览 16

AJAX承诺电话处理

I have an Ember promise call as below;

var promise = new Ember.RSVP.Promise(function(resolve, reject) {
    return $.ajax({
    //want this common
        url: requestUrl,
        type: type, // HTTP method
        dataType: dataType, // type of data expected from the API response
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(postData)
    })
    .done(function(data, status, xhrObject) {
    //But want this to be different
      // resolve call
    })
    .fail(function(xhrObject, status, error){
      // reject call
    });
})

My question is can I use common code for $.ajax(), but have different implementation for done() callback I can check that by passing some parameter from the calling place.

so basically, I want

if (someparam == 'handleDone1')
    call resolve(data)
else
    call resolve({data})
  • 写回答

2条回答 默认 最新

  • weixin_33713503 2016-05-27 10:28
    关注

    You are currently passing a function to done by hard coding a function expression into it.

    Replace that with a variable. Pass a value to that variable as a function argument.

    Alternatively, don't use done here at all. Just return the return value of $.ajax() and call done() on that in the calling function.

    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建