gpt4 book ai didi

javascript - Polymer JS POST JSON 格式

转载 作者:行者123 更新时间:2023-12-03 10:04:51 25 4
gpt4 key购买 nike

我正在尝试使用 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 在日志中可见:

{ title: "WRU", // rest of key & values, where the keys are without the "" }

最佳答案

您需要先将正文转换为 JSON 字符串。 JSON.stringify 可以提供帮助。

...
createNewCourse: function(e) {
this.$.postCourse.body = JSON.stringify(this.item);
this.$.postCourse.go();
}

您可能需要在此处删除 body 属性。您还可以删除该 auto 属性,因为默认情况下它是 false。

关于javascript - Polymer JS POST JSON 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30404138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com