FormData from JS
Posted: Wed Apr 21, 2021 9:22 am
Hi everyone,
Is there any way to get formData sent from JS to avoid reloading a web page after sending? For example, I do a get using CallBackFunctionPageHandler and this is done correctly, but I can't find the way to post.
For example, for the post I did:
.cpp
int callbackCloseConfig(int sock, HTTP_Request &pHttpRequest)
{
SendHTMLHeader(sock);
//do something
open_close = false;
return 1;
}
CallBackFunctionPageHandler getHandlerClose("close_config.html", callbackCloseConfig, tGet, 0, false);
.js
function httpGetClose(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false ); // false for synchronous request
xmlHttp.send( null );
}
Now, I have my function in JS for the post that will send all the data, how do I develop the function that receives that dataform and processes the fields there in my NB?
.js//my send js function
function sendForm() {
var data = new FormData(document.getElementById("fileinfo"));
var xhr = new XMLHttpRequest();
xhr.open("POST", "post_config.html", false)
xhr.send(data);
if (xhr.status == 200) {
//do something
} else {
//do something
}
}
I know that HtmlPostVariableListCallback exists but that would force me to reload the page.
I will appreciate all the possible help
Thanks
Fredy
Is there any way to get formData sent from JS to avoid reloading a web page after sending? For example, I do a get using CallBackFunctionPageHandler and this is done correctly, but I can't find the way to post.
For example, for the post I did:
.cpp
int callbackCloseConfig(int sock, HTTP_Request &pHttpRequest)
{
SendHTMLHeader(sock);
//do something
open_close = false;
return 1;
}
CallBackFunctionPageHandler getHandlerClose("close_config.html", callbackCloseConfig, tGet, 0, false);
.js
function httpGetClose(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false ); // false for synchronous request
xmlHttp.send( null );
}
Now, I have my function in JS for the post that will send all the data, how do I develop the function that receives that dataform and processes the fields there in my NB?
.js//my send js function
function sendForm() {
var data = new FormData(document.getElementById("fileinfo"));
var xhr = new XMLHttpRequest();
xhr.open("POST", "post_config.html", false)
xhr.send(data);
if (xhr.status == 200) {
//do something
} else {
//do something
}
}
I know that HtmlPostVariableListCallback exists but that would force me to reload the page.
I will appreciate all the possible help
Thanks
Fredy