I am using a basic node.js introduction script, and i am passing in a argument in the command line. i want this argument to be passed back to the client after it has run. I can pass back anything that is pure text or values, but i can't pass back a variable containing the same information.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>get test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js">
</script>
</head>
<body>
<h1>Get Test</h1>
<div id="test"></div>
<script>
$(document).ready(function() {
$.ajax({url: 'http://localhost',dataType: "jsonp",jsonpCallback: "_testcb",cache: false,timeout: 5000,success: function(data) {
$("#test").append(data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert('error ' + textStatus + " " + errorThrown);
}
});
});
</script>
</body>
</html>
And this is my server code:
var http = require('http');
var arr = new Array();
http.createServer(function (req, res) {
res.writeHead(200);
// print process.argv
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
arr[index] = val;
res.write("Size" + val);
res.end('_testcb(\'{"Size: \' + val + \'"}\')');
});
console.log(arr[2]);
}).listen(80);
So my question is, how do i pass back objects/ variables/ arrays rather than static text?