This is my JavaScript function: I get this function by google it.
function postURL() {
var jobValue = document.getElementsByName('folderName')[0].value;
url = 'http://localhost:8888/TaaS/Sachin/Input' + "?FolderName=" + jobValue;
var form = document.createElement("FORM");
form.method = "POST";
//if(multipart) {
form.enctype = "multipart/form-data";
//}
form.style.display = "none";
document.body.appendChild(form);
form.action = url.replace(/\?(.*)/, function(_, urlArgs) {
urlArgs.replace(/\+/g, " ").replace(/([^&=]+)=([^&=]*)/g, function(input, key, value) {
input = document.createElement("INPUT");
input.type = "hidden";
input.name = decodeURIComponent(key);
input.value = decodeURIComponent(value);
form.appendChild(input);
});
return "";
});
form.submit();
}
I call this function during onclick;
<button type="submit" class="btn btn-primary start" onclick="postURL()">
<i class="glyphicon glyphicon-upload"></i>
<span>Create Folder</span>
</button>
I am using node.js in my server side. During the button click event in server side, the POST method is calling, but I don't know how to retrieve the "jobValue" in node.js file during POST method.
POST Method:
function(req, res) {
switch (req.method) {
case 'OPTIONS':
res.end();
break;
case 'POST':
console.log('req.url: ' + req.url);
break;
default:
res.statusCode = 405;
res.end();
}
}
How to get that value in node.js file?
You didn't specify but I'm going to assume you're using Express on the server side. Despite POSTing a form, you're sending the jobValue as a query string parameter (FolderName) in the example so you'd get it in the handler function with:
req.query.FolderName
In the context of your callback:
function(req, res) {
switch (req.method) {
case 'OPTIONS':
res.end();
break;
case 'POST':
var jobValue = req.query.FolderName; //<-- Your variable
console.log('req.url: ' + req.url);
break;
default:
res.statusCode = 405;
res.end();
}
}