PolymerJS POST JSON formatting
PolymerJS POST JSON formatting
我正在尝试使用PolymerJS ajax-forms POST,我遇到了一个奇怪的JSON格式错误。有人能告诉我为什么钥匙周围没有引号吗?我能想到的唯一解决方法是手动构建带有键周围引号的主体。
代码片段:我如何接收值(其余部分与更改的id相同):
<div>
<paper-input label="Title" id="course-title" floatingLabel value="{{item.title}}"></paper-input>
</div>
<access-core-ajax
auto = "false"
url="domain/courses"
response="{{response}}"
method="post"
id="postCourse"
contentType="application/json"
headers='{"Accept": "application/json", "Content-Type":"application/json"}',
body = "{{item}}">
<template id="get-response-template" repeat="{{item in response.entries}}">
<p>Errors</p>
</template>
</access-core-ajax>
Polymer('create-new-course-page',{
domReady: function() {
console.log("Log: create-new-courses-page - Looks like we are domReady");
},
created: function() {
console.log("Item initialized");
this.item = {};
this.data={};
},
createNewCourse: function(event) {
console.log("HERE IS BODY", this.item);
this.$.postCourse.go();
}
JSON可以在日志中看到:
{标题:"WRU",//键的剩余&值,其中键不带"}
首先需要将正文转换为JSON字符串。JSON。Stringify可以提供帮助。
...
createNewCourse: function(e) {
this.$.postCourse.body = JSON.stringify(this.item);
this.$.postCourse.go();
}
您可能需要删除这里的body属性。您还可以删除auto属性,因为默认情况下它是false。
相关文章:
- jQuery匹配JSON对象的部分文本
- 在循环中分配json值时,值被覆盖
- 需要帮助设置json数组
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 使用JQuery解析JSON嵌套数组
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 如何使用json将对象列表从java转换为javascript
- 如何使用 node.js 比较两个 json 数组
- 如何将JSON数据导入我的ejs模板
- 区分JSON中的矩阵和列表列表
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 如何为json对象中的段发送array[]
- Formatting response JSON data using AngularJS & ExpressJ
- HapiJS JSON Formatting
- node.js + json formatting
- PolymerJS POST JSON formatting