好的,我有2個工作腳本至極我試圖與對方先在結合使用是我的javascript通過JavaScript發送陣列的NodeJS
<script type="text/javascript">
function textareaToArray(t){
return t.value.split(/[\n\r]+/);
}
function showArray(msg){
for(i = 0; i < msg.length; i++) {
// something per item
alert(msg[i]);
}
// the old code
document.getElementById("message").innerHTML = msg.join("
");
}
</script>
,然後我有一個節點js腳本至極接受POSTDATA
http://localhost.com/?name=Data
basicaly它在我的JavaScript說
alert(msg[i]);
我想POSTDATA
localhost.com/?name=味精[I] < <這是我所想要做的
var url = require('url');
var http = require('http');
var server = http.createServer(function (request, response) {
var queryData = url.parse(request.url, true).query;
response.writeHead(200, {"Content-Type": "text/plain"});
if (queryData.name) {
// user told us their name in the GET request, ex: http://host:8000/?name=Tom
var basevalue = queryData.name;
var value = basevalue.split (":");
var exec = require('child_process').exec;
console.log(value[0]);
exec ("casperjs test.js " + value[0] + " " + value[1] + '\n',function(err, stdout, stderr) {
response.end('data sent');
});
} else {
response.end("Contact Admin - Not Working\n");
}
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(process.env.PORT);
我的Java腳本Ø遠
<script type="text/javascript">
function textareaToArray(t){
return t.value.split(/[\n\r]+/);
}
function showArray(msg){
for(i = 0; i < msg.length; i++) {
// something per item
var data = {}; //your own data
$.post("https://new-c9-ashg1990.c9.io" + "?" + $.param({name: msg[i]}), data);
alert(msg[i]);
}
// the old code
document.getElementById("message").innerHTML = msg.join("
");
}
</script>
u能解決的例子我上面的代碼,所以它顯示我的迴應node.js
你是什麼意思「發佈數據」?你想要做一個http發佈請求嗎? –