this article illustrates the simple web server functionality of the nodejs implementation. Share to you for your reference, as follows:

JS

 < front-end code: script "jquery-1.12.1.js" > src=; < /script> < script > type= "text/javascript" $.ajax ({url:'http://192.168.0.114:3000'/ / server address, type:'post', timeout:30, dataType:'json', data:{"username" username, password "" password: success:function (RES)}, {console.log (JSON.stringify (RES));}, {err:function (ERR) alert (ERR);}}); 

nodejs

 var Code: 

HTTP = require ('http'); VAR url = require ('url'); VAR QS = require ('querystring') http.createServer; function ((req, RES) {res.writeHead (200, {'Content-Type':'text/plain; charset=UTF-8','Access-Control-Allow-origin': if (req.method.toUpp'*'}); (erCase) = ='GET') {var query = url.parse (req.url, true).Query; / / accept data res.end (JSON.stringify (query));}else (if) (req.method.toUpperCase = ='POST') {var postData = ''; req.on ('data', function (data) {postData = data;} / / receive data); req.on ('end', function) {var (query = qs.parse (postData); res.end (JSON.stringify (query)); / / return data}}});.Listen ('3000'), function () {console.log ('This is callback');}); console.log ('server is running')

; I hope this the nodejs program designed to help you.

This paper fixed link:http://www.script-home.com/an-example-of-the-simple-web-server-functionality-implemented-by-nodejs.html | Script Home | +Copy Link

Article reprint please specify:An example of the simple web server functionality implemented by nodejs | Script Home

You may also be interested in these articles!