javascript - Print received data from client in NodeJS server -


i have simple html file containing piece of javascript:

<script type="text/javascript">             $.ajax({             url: 'http://192.168.x.x:8080',             data: '{"data": "1"}',             datatype: "jsonp",             cache: false,             timeout: 5000,             success: function(data) {                     var ret = jquery.parsejson(data);                 },                 error: function (xhr, status, error) {                     console.log('error: ' + error.message);                     document.getelementbyid("error").innerhtml = 'error: ' + error.message;                 }             });     </script> 

i want nodejs server print data received (there: number 1°).

here nodejs code:

var http = require('http'); var s = http.createserver(); s.on('request', function(request, response) {     response.writehead(200);     console.log('a: '+request.method);     console.log('b: '+request.headers);     console.log('c: '+request.url); }); s.listen(8080); 

server receiving requests find how retrieve value of data sent? want server receive number client , print it. how that?

many thanks1

i think looking for.

#!/usr/bin/node   var http = require('http'); var s = http.createserver(); s.on('request', function(request, response) {     response.writehead(200);     console.log('a: '+request.method);     console.log('b: '+request.headers);     console.log('c: '+request.url);      var url = decodeuricomponent(request.url);     var startpos = url.indexof('{');     var endpos = url.indexof('}');     var jsonstring = url.substring(startpos, endpos+1);     json = json.parse(jsonstring);     console.log(json['data']) }); s.listen(8080); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -