PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

on-request callback does not modify request body #270

Closed victorbucutea closed 7 years ago

victorbucutea commented 7 years ago

Description

Unable to modify request body before it is sent to server side ( on-request event ):

<iron-ajax id="datapointRequest" url="/xxx/v1/datapoints" method="post" on-request="_timeseriesQuery" on-response="_initChartData"></iron-ajax>

` _timeseriesQuery: function (event) {

  // query last month's data
  var start = new Date();
  start.setMonth(start.getMonth() - 1);
  start.setDate(1);
  var end = new Date();
  var query = {cache_time: 0, start: start.getTime(), end: end.getTime()};

  event.detail.request.set('body', query);
  event.detail.options.body = query;
}`

Actual outcome

neither of the above setters will have any effect on the request body

e111077 commented 7 years ago

I think you may be looking for on-iron-ajax-presend. Does this work?

victorbucutea commented 7 years ago

Aha. Issue is behind me, but seems like the good way to go