從我的網絡(客戶端)的機器之一返回數據,我正在$.ajax()
請求我Nodejs
服務器一樣,
//Client : index.html
$.ajax({
type:"post",
url:'http://192.168.2.6:8080',
data:JSON.stringify({"loginData":{"uanme":"maverick","upass":"asd"}}),
success:function(data){console.log(data);alert(data);},
error:function(){alert('Error aala');}
});
和我Nodejs
服務器是
//listener.js
var server = require('http').createServer(function (request, response) {
var body='';
if(request.method=='POST'){
request.on('data',function(data){
body+=data;
});
request.on('end',function(){
console.log(body);
});
}
}).listen(8080);
這些console.log()
s工作非常好。我得到我的節點側發送完全相同的數據,
現在的問題是,在php
當我們做一個$.ajax()
要求,我們使用echo
在我們的PHP文件,將數據發送回客戶端,
如果我想將數據發送回客戶端,我需要在服務器端做些什麼Nodejs (listener.js file)
?
'response' http://nodejs.org/api/http.html#http_response_end_data_encoding – ashley 2013-02-15 12:52:33