在AJAX中传递多个数据

问候。 我想传递多个数据到我的服务器代码。 请find我的程序的下面的stream程。 HS110:

function turnplug2On(){ var newval=this.getAttribute("data-id"); var newval1=this.getAttribute("data-id2"); newval=newval+"On" console.log(newval); $(document).ready(function() { //console.log(newval); $.ajax({ type: "POST", url: 'http://localhost:8124/', timeout: 2000, data: JSON.stringify({data:newval}), //data: '{"data":"plug2On"}', //data:newval, }); }); } $(document).ready(function () { Array.from(document.getElementsByClassName("turn-on")).forEach(function (button) { button.onclick = turnplug2On; }); }); ajax.js: http.createServer(function (req, res) { //console.log('request received'); //util.log(util.inspect(req)); console.log(req,res); res.writeHead(200, {'Content-Type': 'text/plain'}); req.on('data', function (chunk) { console.log(chunk.toString()); //req.on(function (chunk) { var obj = JSON.parse(chunk.toString()); console.log(obj.data); 

你能帮我怎么传递对象data-id2到服务器和如何处理作为一个单独的数据? 提前致谢

 var newval=this.getAttribute("data-id"); var newval1=this.getAttribute("data-id2"); newval=newval+"On" console.log(newval); $(document).ready(function() { //console.log(newval); $.ajax({ type: "POST", url: 'http://localhost:8124/', timeout: 2000, data: JSON.stringify({newval:newval,newval1:newval1}), //data: '{"data":"plug2On"}', //data:newval, }); }); }