【问题标题】:Unable to connect with a google backend from Wix无法从 Wix 连接到谷歌后端
【发布时间】:2021-04-02 12:09:55
【问题描述】:

我已经构建了一个机器学习后端并将其部署在谷歌云上。当我从带有一些数据的 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));
}

【问题讨论】:

    标签: javascript frontend velo


    【解决方案1】:

    解决方案是在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));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      相关资源
      最近更新 更多