Send JSON value to Server with Socket.io from jQuery
I'm havingo some troubles to send a value from a JSON object to my Node.js server through Socket.io
Here is my code in jQuery for the client. The problem comes when trying to emit the event "check-Services". The server doesn't receive anything...
var socket = io(); socket.emit('DB-Update'); socket.on('Update-Time', function(update_time){ var date = $('Última modificación: '+update_time+''); $('#database-info').append(date); }); socket.on('DB-Info', function(serviceList){ for(var i=0; i'+serviceList[i].nombre+'
'+serviceList[i].url+''); } else{ var newService = $(''+serviceList[i].nombre+'
'+serviceList[i].url+''); } var newButton=$('').attr({ type: "button", id: serviceList[i].nombre, value: 'Comprobar '+serviceList[i].nombre, class: "service-button btn btn-primary", }); $("#database-info").append(newService); $("#services-buttons").append(newButton); $("#"+serviceList[i].nombre).click(function(event){ var obj = serviceList[i].nombre; socket.emit('check-Services', obj); event.preventDefault(); }); } });
In the server I'm simply trying to print out in the console the data comming from the client. I also send some data from the server to the client in the same way (servicesList is received like that from the server) and there wasn't any problem...
链接地址: http://www.djcxy.com/p/82588.html上一篇: 友好的版本不起作用