I recently have problems binding data from input element to iron-ajax's "body" attribute. When I used core-ajax on polymer 0.5, I can easily bind values like this:
<core-ajax
id="ajax"
method="POST"
contentType="application/json"
url="{{url}}"
body='{"username":"{{username}}", "password":"{{password}}"}'
handleAs="json"
on-core-response="{{responseHandler}}">
</core-ajax>
Now I tried the same thing with iron-ajax. But it sends literally "{{username}}" and "{{password}}" instead of their values. Here is the code:
<iron-ajax
id="ajax"
method="POST"
contentType="application/json"
url="{{url}}"
body='{"username":"{{username}}", "password":"{{password}}"}'
handle-as="json"
on-response="responseHandler">
</iron-ajax>
How to make it work? Thank you for your answers :)
You can declare a computed property for the ajax body. Like so
properties: {
...
ajaxBody: {
type: String,
computed: 'processBody(username, password)'
}
},
processBody: function(username, password) {
return JSON.stringify({username: username, password:password});
}
And then adding it on iron-ajax
<iron-ajax ... body="{{ajaxBody}}"></iron-ajax>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With