【发布时间】:2018-07-31 19:11:14
【问题描述】:
我正在尝试与第 3 方 API 进行通信。我用python编写了API。我想使用用户表单和文本框从 Wix 网页更新数据库中的名称列。数据库更新和所有端点都使用邮递员进行响应测试。我认为问题在于我在 Wix 端的 JavaScript。
我在以下位置对 Wix 示例中的 JavaScript 进行了建模: https://support.wix.com/en/article/calling-server-side-code-from-the-front-end-with-web-modules
我有一个名为 placeOrder 的后端模块存储在 orderplaced.jsw 中,它应该将变量“名称”发布到 api。
import { fetch } from 'wix-fetch';
// wix-fetch is the API we provide to make https calls in the backend
export function placeOrder(name) {
return fetch("https://reliableeparts.pythonanywhere.com/user", {
method: 'post',
name: JSON.stringify({ name })
}).then(function (response) {
if (response.status >= 200 && response.status < 300){
console.log(JSON.stringify({ name }))
return response.text();}
console.log(Error(response.statusText))
return Error(response.statusText);}
);
}
前端模块等待按钮单击并将文本框存储在名称变量中。
{
import {placeOrder} from 'backend/orderplaced.jsw';
export function button1_click(event, $w) {
placeOrder(
$w("#input1").value)
.then(function() {
console.log("Form submitted to backend.");
}
);
}
}
输出: 2 代码似乎到达了后端。我相信问题出在我的 placeOrder 函数上,因为我对 JavaScript 不是很熟悉。
【问题讨论】:
标签: javascript velo