我试图使用PolymerJS ajax-forms发布文章,但遇到了一个奇怪的JSON格式错误。有人能告诉我为什么钥匙周围缺少引号吗?我能想到的唯一解决办法是用键周围的引号手动构造主体。
代码片段:如何接收值(rest与更改的ids相同):
<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",// key & values,其中键没有"“}
发布于 2015-05-23 05:37:03
您需要首先将主体转换为JSON字符串。JSON.stringify可以帮上忙。
...
createNewCourse: function(e) {
this.$.postCourse.body = JSON.stringify(this.item);
this.$.postCourse.go();
}您可能需要在这里移除body属性。您还可以删除该auto属性,因为默认情况下它是false。
https://stackoverflow.com/questions/30404138
复制相似问题