我有一个问题,我想使用带有json数据的PUT方法但是它在查询字符串参数中传递这些参数而不是在json中,我找不到我的错误。如果可能的话,我不想使用'iron-ajax'。
<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>
谢谢大家的帮助!
答案 0 :(得分:1)
iron-form
仅包含POST
个请求正文中的参数。最简单的解决方法是将method="put"
更改为method="post"
,并为iron-form-presubmit
添加处理程序(序列化后触发),将方法更改回PUT
。
form.addEventListener('iron-form-presubmit', function() {
this.request.method = 'put';
});