Hi
I have this code which was working for a long time, and suddently stoped working for 2 websits
It posts form data to an external enpoint.
I keep receiving " TypeError: Failed to fetch"
I also created an endpoint on my test server to recieve this post request, it works on POSTMAN, but getting the same error hwen trying in wix corvid.
the code:
export function submit_click(event) {
console.log(-1);
console.log(“Function called”)
//Add your code for this event here:
let res = onSubmit(
{
Email : ‘tetsttest@gmail.com’,
Mobile : ‘555555555’,
Last_Name : ‘last’ ,
First_Name : ‘first’,
Site_Page : wixSite.currentPage[‘name’] ,
Form : “Contact us”
}
/*{
Email : $w(‘#mail’).value,
Mobile : $w(‘#phone’).value,
Last_Name : $w(‘#last’).value ,
First_Name : $w(‘#first’).value,
Lead_Source : getDefualtSource() ,
Lead_Status : getDefualtStatus() ,
Site_Page : wixSite.currentPage[‘name’] ,
Course_Name : ‘NA’ ,
Form : “Contact us”
} */
)
console.log(-2)
console.log(res)
}
import {fetch} from ‘wix-fetch’;
export function onSubmit(data){
let url = “myURL”;//cannot publish here , has sensitive data
let headers = { “Content-Type”:“application/json”};
console.log(JSON.stringify(data));
let meta = {“method”: “POST”,“headers”:headers, body: JSON.stringify(data)};
let res = fetch(url,meta)
.then(
(httpResponse) => {
if (httpResponse.ok) {
console.log(httpResponse)
return httpResponse.json();
}
}
)
.then(json => console.log(json.someKey))
. catch (
err => console.log(err)
);
}
}