【发布时间】:2020-02-22 19:00:57
【问题描述】:
如何将数据添加到网站上已有的 .json 文件中?我有点了解您如何在本地将数据添加到 .json,但如果我需要将其发送到已经创建和托管的文件。
这是我的 server.js 文件中的代码
router.post('/themes', async (ctx) => {
const results = await fetch(`https://`+ ctx.cookies.get("shopOrigin") + `/admin/themes.json`, {
headers: {
"X-Shopify-Access-Token": ctx.cookies.get('accessToken'),
},
})
.then(response => response.json());
ctx.body = {
status: 'success',
data: results
};
});
这是我的前端 .js 文件中的代码
async function getUser() {
const query = [
{
"theme": {
"name": "Lemongrass",
"src": "https://codeload.github.com/Shopify/skeleton-theme/zip/master"
}
}
]
var url = "/themes";
var method = 'post';
fetch(url, { method: method, body: query})
.then(response => response.json())
.then(json => console.log(json))
};
我可以在控制台上提取数据,也就是主题,但是,我需要发送数据以便创建新主题。
【问题讨论】:
标签: javascript json shopify shopify-app