【问题标题】:Sending data in 'Request Payload' using amplifyjs使用 amplifyjs 在“请求有效负载”中发送数据
【发布时间】:2013-03-07 06:03:18
【问题描述】:

我有一个 javascript 对象要发送到服务器,如下所示:

var input = {a: 'aaa', b: 'bbb', c: 'ccc'};

我想像这样在 url 中发送 'a' 属性

http://localhost/rest/customer/aaa

使用 amplifyjs 中的 url 替换功能很好,如下所示:

amplify.request.define('update-customer', 'ajax', {
    url : 'rest/customer/{a}',
    dataType: 'json',
    type : 'PUT'
    contentType : 'application/json; charset=utf-8;
});

amplify.request('update-customer', { a : input.a, data : input });

我正在努力解决的问题是,我想将 b 和 c 属性作为 json 格式的表单数据作为“请求有效负载”发送,但是由于表单数据发送如下:

Request Payload :
  data : {b : 'bbb', c : 'ccc'}

所以我想要实现的是删除“请求有效负载”中的 'data' 键,如下所示:

Request Payload :
 {b : 'bbb', c : 'ccc'}

我在 REST Client 程序中对此进行了测试,并且成功了。

结束我的问题,如何使用 amplifyjs 发送没有键名的请求正文中附加的数据? 提前致谢。

【问题讨论】:

    标签: amplifyjs


    【解决方案1】:

    尝试:

    amplify.request.define('update-customer', 'ajax', {
      url: 'rest/customer/{a},
      dataType: 'json',
      type: 'PUT',
      contentType: 'application/json; charset=utf-8',
      data: {
        b : '{b}',
        c : '{c}'
      }
    });
    
    amplify.request('update-customer', { a : input.a, data : input });
    

    如果 input.b 或 input.c 为空,此解决方案会出现问题。 Check this post for further details

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多