无法连接 Wix 的 google 后端
Unable to connect with a google backend from Wix
我已经构建了一个 ML 后端并将其部署在 google 云上。当我使用一些数据从 wix 前端表单调用后端时,出现以下错误:
我使用以下代码在单击按钮时执行此操作。
export function button1_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
var data = $w("#textBox1").value;
var raw = JSON.stringify({"data":data});
var requestOptions = {
method: 'POST',
body: raw,
redirect: 'follow'
};
var url = "https://url-for-google-webapp"
fetch(url, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
解决方法是在 onReady()
中定义 URL 并将其保存在本地存储
import {local} from 'wix-storage';
$w.onReady(function () {
local.setItem("url", "https://the-url-you-want-to-visit")
});
然后在 button1_click(event)
方法中检索设置变量:
export function button1_click(event) {
...
var url = local.getItem("url")
fetch(url, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
我已经构建了一个 ML 后端并将其部署在 google 云上。当我使用一些数据从 wix 前端表单调用后端时,出现以下错误:
我使用以下代码在单击按钮时执行此操作。
export function button1_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
var data = $w("#textBox1").value;
var raw = JSON.stringify({"data":data});
var requestOptions = {
method: 'POST',
body: raw,
redirect: 'follow'
};
var url = "https://url-for-google-webapp"
fetch(url, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
解决方法是在 onReady()
中定义 URL 并将其保存在本地存储
import {local} from 'wix-storage';
$w.onReady(function () {
local.setItem("url", "https://the-url-you-want-to-visit")
});
然后在 button1_click(event)
方法中检索设置变量:
export function button1_click(event) {
...
var url = local.getItem("url")
fetch(url, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}