【发布时间】:2021-09-09 22:52:06
【问题描述】:
我有一个配置为发送包含表单数据的电子邮件并仅在页面上显示确认消息的 Wix 表单。我被要求添加第二个请求以将相同的表单数据发送到不同的服务器。我能够使用 onWixFormSubmited() 将数据发送到后端
export function wixForms1_wixFormSubmitted() {
let data = {
first_name: $w('#input5').value,
last_name: $w('#input4').value,
email: $w('#input3').value,
}
saveProspectToCRM(data)
.then(function(response) {
console.log('it was successfull');
console.log(response);
});
}
import {fetch} from 'wix-fetch';
export async function saveProspectToCRM(params) {
const url = 'myurl';
let data = {
//encoded data
};
return fetch(url,{
method: 'post',
body: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}).then(function(response) {
if (response.status >= 200 && response.status < 300) {
return response.text();
} else {
throw new Error(response.statusText);
}
});
}
这确实有效,并且正在发送电子邮件并将数据发布到我的另一台服务器,但我有第二个 Wix 表单,唯一的区别是这个表单在提交后重定向到不同的页面,而不是仅仅显示一条消息。而且我的代码不适用于第二种形式。我尝试将 onWixFormSubmitted 更改为 onWixFormSubmit 但仍然无法正常工作。
我在文档中读到onWixFormSubmit 只处理同步操作,我假设第一个表单有效,因为用户没有被重定向到不同的页面。任何人都可以告诉我我做错了什么,或者保持表单配置(发送电子邮件)并将数据发布到服务器的最佳方法是什么?
【问题讨论】:
标签: javascript node.js httprequest velo