I am having an issue attempting to receive post data without first running the html page from a web browser. I was wondering if there is a way using NodeJS that someone could run a given html document silently retrieving only the Post data and the console output. I need this in order to allow development in a cloud or remote server environment.
Current Usage Server.js :
var spawn = require('child_process').spawn; // Will not do for the situation of development within something similar to an Ubuntu Server
spawn(command, ["http://localhost:80/Develop/Client.html"]);
http.createServer(mainArgs).listen(options); // mainArgs is the function (req,res) callback
function mainArgs(req,res){
if (req.method == 'POST') { // NodeJS is Getting what is posted...
console.log("POST");
var url_parts = url.parse(req.url, true);
currentQuery = url_parts.query;
req.on('end', function () {
console.log("Body: " + currentQuery['stubScript']);
writeHTML(currentQuery['stubScript']);
});
}
..... // HTML, JavaScript, & CSS Handled here
}
Current Usage Client.html :
<html>
<head>
//Posts data via XMLHttpRequest()
<script src=devScript.js></script>
</head>
<body>
<script>
// Access Devscript functions and build page using javascript
</script>
</body>
</html>
Current Usage devScript.js :
function postIt(varname, variable) {
var req = new XMLHttpRequest();
var getParms = '?'+ varname + '=' + variable;
req.open('POST', document.URL + getParms, true);
req.onreadystatechange = function(){
if (req.readyState == 4 && req.status == 200)
{
alert('PHPcall() : JSObject =' + varname );
}
};
req.send(getParms);
} // Client is posting...