I'm currently working with the Polymer 2 library and facing an issue when making multiple requests using iron-request. It seems that only the first request, which is a POST request, gets initiated successfully. Subsequent requests appear to be ignored, even if the data being sent to the server is different from the initial request.
To illustrate this problem, I have created a small example on Plunker: https://plnkr.co/edit/cozVKUdQ2q2SV46rcCTL?p=preview
In this example, I've set up an iron-request element and a button element to trigger the request like so:
<paper-button on-click="save" class="green">Send</paper-button>
...
<iron-request id="xhr"></iron-request>
The save function captures text input from a textarea and sends it to the server:
save() {
var response = this.$.xhr.send({
url: "https://httpbin.org/post",
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
body: {
content: this.inputdata
},
method: "POST"
});
var poly = this;
this.$.xhr.completes.then(function(data) {
console.log("finished");
poly.$.responsetext.innerHTML = data.response;
})
The specific code causing the issue can be found in the "element1.html" file. If you attempt to send different text payloads, you'll notice that only the initial request goes through (as seen by the unchanged "content" field in the response).
Any insights into what might be causing this behavior? My current thought is that I may need to create new iron-request elements for each new request, but that doesn't seem like the most elegant solution.