XMLHttpRequest GET params undefined in request nodejs api
As mentioned, GET or HEAD requests cannot have a body.If your data is large, you should move to a POST request.
However, if the parameters you want to use are short like the ones in the example, you should use query strings:
var url = "bla.php";var params = "somevariable=somevalue&anothervariable=anothervalue";var http = new XMLHttpRequest();http.open("GET", url+"?"+params, true);http.send(null);
on the node side, assuming you use express, you can read the variables using:
var somevariable = req.query.somevariable;var anothervariable = req.query.anothervariable;
From XMLHttlRequest.send()
docs:
... If the request method is GET OR HEAD,the argument is ignored and the request body is set to null.
Change your sending method to POST.