I have a problem with my , I want to use the PUT method with json data but it's passing those parameters in the query string parameters and not in json, and I can't find my mistake. I'd like not to use 'iron-ajax' if possible.
<form is="iron-form" method="put" action="http://localhost:5000/users/" id="loginForm" content-type="application/json">
<paper-input name="username" label="Username" required auto-validate></paper-input>
<paper-input name="password" label="Password" type="password" required auto-validate></paper-input>
<paper-button raised onclick="_submit(event)" disabled id="loginFormSubmit">
<paper-spinner id="spinner" hidden></paper-spinner>Submit</paper-button>
<paper-button raised onclick="_reset(event)">Reset</paper-button>
<div class="output"></div>
</form>
<script>
loginForm.addEventListener('change', function(event) {
loginFormSubmit.disabled = !loginForm.validate();
});
function _submit(event) {
spinner.active = true;
spinner.hidden = false;
loginFormSubmit.disabled = true;
Polymer.dom(event).localTarget.parentElement.submit();
}
function _reset(event) {
var form = Polymer.dom(event).localTarget.parentElement
form.reset();
form.querySelector('.output').innerHTML = '';
}
document.getElementById('loginForm').addEventListener('iron-form-submit', function(event) {
spinner.active = false;
spinner.hidden = true;
loginFormSubmit.disabled = false;
this.querySelector('.output').innerHTML = JSON.stringify(event.detail);
});
document.getElementById('loginForm').addEventListener('iron-form-response', function(response) {
console.log(response);
});
</script>
thank you all for your help !
iron-form
only includes the parameters in the body of POST
requests. The simplest workaround is to change your method="put"
to method="post"
, and add a handler for iron-form-presubmit
(fires after serialization) to change the method back to PUT
.
form.addEventListener('iron-form-presubmit', function() {
this.request.method = 'put';
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.