I'm trying to get away from jQuery by using fetch to post form data.
I have no trouble using formData = new FormData(frmMain) to post data using fetch - However the example below is from the developer.mozilla.org web site and it doesn't work for me. The web server does not read in the stringified JSON.
postData(`http://example.com/answer`, {answer: 42})
.then(data => console.log(JSON.stringify(data)))
.catch(error => console.error(error));
function postData(url = ``, data = {}) {
return fetch(url, {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
redirect: "follow",
referrer: "no-referrer",
body: JSON.stringify(data)
})
.then(response => response.json()); // parses response to JSON
}
Are you making a cross site call? Differnent Web site or even same machine, different port? If so, CORS may be preventing the calls from working...
+++ Rick ---
The web server registers the requested data OK, but variables do not get imported . I'm using
Dimension laVars[1,2] lnVars = Request.aFormVars(@laVars)
It that CORS related? I'm using localhost/wconnect as the server.
That's because JSON is not a form variable request. You can only get the raw JSON data. Use Request.Form()
to retrieve the JSON then deserialize it and get the value out. Or use a REST Service which will handle all that for you.
+++ Rick ---