javascript - Ajax send data to Node.js client then send to Node.js server -
is possible jquery.ajax send data node.js client,then after receive data send node.js server ?. possible ?
myajax
$.ajax({ type:'post' data:{data:hello}, url: '' //here don't know how point node.js client success:function(data){ } });
servarapp.js
var net = require('net'); var clients = []; var server = net.createserver(function (socket) { clients.push(socket); }); server.listen(1337,'localhost',function(){ console.log("server listening in port 1337"); });
client.js
var net = require('net'); var client = new net.socket(); client.connect(1337, '127.0.0.1', function() { console.log('connected'); client.write('hello, server!); }); client.on('data', function(data) { console.log('received: ' + data); client.destroy(); }); client.on('close', function() { console.log('connection closed'); });
thank in advance.
an ajax request browser can sent http server. in client.js
seem have created socket on port 1337 cannot work because ajax through http protocol. work can use http framework such express
create http server.
Comments
Post a Comment