简体   繁体   English

聚合物铁型PUT方法在url中传递参数

[英]polymer iron-form PUT method pass parameters in url

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. 我有问题,我想对JSON数据使用PUT方法,但是它在查询字符串参数中而不是在json中传递那些参数,而且我找不到我的错误。 I'd like not to use 'iron-ajax' if possible. 如果可能的话,我不想使用'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>

聚合物铁形态误差

thank you all for your help ! 谢谢大家的帮助 !

iron-form only includes the parameters in the body of POST requests. iron-form仅在POST请求的正文中包含参数。 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 . 最简单的解决方法是将method="put"更改为method="post" ,并为iron-form-presubmit添加一个处理程序(序列化后触发),以将方法更改回PUT

form.addEventListener('iron-form-presubmit', function() {
  this.request.method = 'put';
});

codepen 码笔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM