Post-json对象,使用iron-ajax作为application/x-www-form-urlencoded
Post json object with iron-ajax as application/x-www-form-urlencoded
在我的基于Polymer的应用程序中,我想使用与输入元素绑定的奇特JavaScript模型。
将模型POST到我的Spring控制器,但是我想作为经典的formdata执行,这样我就可以利用SpringSessionAttributes。
我这样设置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错误"Cannot read property to String of null"
有可能做我想做的事吗?我的意思是向iron-ajax
传递一个JSON对象,并期望它将其转换为FormData。或者我没有正确使用iron-ajax
?
假设您确信this.mailing
不是null
,则需要首先字符串化它:
this.$.saveMailing.body = JSON.stringify(this.mailing);
相关文章:
- 使用application/x-www-form-urlencoded使用node.js在post请求中发送数组
- 很棒的共享按钮application.coffee文件在哪里
- 通过服务工作者提供OpenSearch“application/x-建议+json”
- jscroll pane in web application
- caching issue with web application developed using reactjs &
- 在spring-boot中使用javascript在application.properties文件中获取值
- 如何将数据/变量从file_controller.rb传递到application.js
- 无法将标头内容类型更改为application/json
- 对GET application/x-jjavascript的Ajax jquery调用
- 在application.js中使用嵌入式ruby
- Application Ionic正在关闭以打开外部URL
- 如何在 express 和 bodyParser中接受 application/csp-report 作为 json
- React & Redux Application Design
- YQL 返回 application/javascript,即使请求 format=json
- $.ajax 响应在 content-Type:application/json 中为 JSON 中的 xml 内容生成
- 如何在使用新的ActiveXObject(“Excel.Application”)时格式化生成的Excel文件;
- ajax, setRequestHeader(), Content-Type, application/x-www-fo
- express.static breaks nodejitsu application
- application.haml 和 application.html.haml 之间的区别
- 为什么 ajax 'application/json' 要运行 PHP 代码两次