【问题标题】:Backbone.js Add URL Parameter for PUT and POST when Saving ModelsBackbone.js 在保存模型时为 PUT 和 POST 添加 URL 参数
【发布时间】:2011-10-21 18:32:34
【问题描述】:

我正在使用 Backbone.js,并且拥有一系列模型。我正在集成的 RESTful 服务要求我向 URL 添加一个“r=true”参数,以在响应中获取模型的 JSON 表示(在 POST 期间取回 id 所需的)。当我调用model.save() 完成POST 或PUT 时,有没有办法将该参数添加到URL?

【问题讨论】:

    标签: post backbone.js put


    【解决方案1】:

    您可以将http://api.jquery.com/jQuery.ajaxPrefilter/ 与以下内容一起使用:

    $.ajaxPrefilter( function( options ) {
        // check if the method is PUT or POST
        // check if there is no parameter, add ?r=true, otherwise add &r=true
        options.url = options.url + "&r=true"; 
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-06
      相关资源
      最近更新 更多