0

I have a javascript object to be sent to server as follow :

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

And I want to send 'a' property in url like this

http://localhost/rest/customer/aaa

That's fine with url substitution feature in amplifyjs as follow :

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 });

The point I am struggling with is that I would like to send b and c property as a form data in json format as a 'Request Payload', however it is failed becauseof the form data is sent as follow :

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

So what I want to achieve is to remove 'data' key in 'Request Payload' as follow :

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

I tested this in REST Client program and was successed.

To wrap up my question, How to send data attached in Request Body without key name using amplifyjs? Thanks in advance.

Ray
  • 4,038
  • 8
  • 36
  • 48

1 Answers1

0

Try with:

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 });

This solution has a problem if input.b or input.c are null. Check this post for further details

Community
  • 1
  • 1
Neuquino
  • 11,580
  • 20
  • 62
  • 76