在我基于 Polymer 的应用程序中,我想使用精美的 JavaScript 模型绑定(bind)到输入元素。
模型到我的 Spring Controller 的 POST,但是我想作为经典表单数据执行,以便我可以利用 Spring SessionAttributes。
我设置了iron-ajax
,如下所示:
<iron-ajax id="saveMailing"
method="POST"
url="/api/mailing"
content-type="application/x-www-form-urlencoded"
on-response="mailingSaved">
</iron-ajax>
我有一个 JavaScript 方法,单击按钮即可执行请求:
saveDraft: function() {
this.$.saveMailing.body = this.mailing;
this.$.saveMailing.generateRequest();
}
this.mailing
是一个 JSON 对象。它不是 FormData()。
结果是我在iron-request.html:421中收到JavaScript错误“无法读取null的属性toString”
有可能做我想做的事吗?我的意思是传递一个 JSON 对象并期望它将其转换为 FormData。或者我没有正确使用iron-ajax
?
最佳答案
假设您确定 this.mailing
不是 null
,您需要先将其字符串化:
this.$.saveMailing.body = JSON.stringify(this.mailing);
关于javascript - 使用 iron-ajax 作为 application/x-www-form-urlencoded 发布 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34401893/