bodyParser parses already json for you, if the Content-Type is set right,
in your case you should set datatype to 'json'. so non need to parse it
again. i'm not sure what your problem is really. the logged strings are not
a good way to check if the recieved data is in proper format. you should do
something like if (req.body.DistrictCode == '12') console.log('successful
transmition')
Am Mittwoch, 15. Mai 2013 14:29:00 UTC+2 schrieb Srividhya:
>
> Hi all,
> I can't able to get the request data in proper format which is coming
> from ajax call through html page. Here clienside am using html page calling
> nodejs service through ajax request and on server side am using nodejs
> express framework and the method used is post. I will send the code what i
> wrote. Pls anyone tell how to solve this.
>
> on server side am using this :
> -------------------------------------------
> var http = require('http');
> var pg = require('pg');
> var express = require('express')
> var app = express.createServer();
>
>
> app.use(express.bodyParser());
>
> app.post('/getTaluk', function(request, response){
> console.log("enters :::");
>
> var stringData = JSON.stringify(request.body);
> var stringData1 = JSON.parse(stringData);
> var stringData2 = JSON.stringify(stringData1);
> console.log("stringData =========>"+stringData);
> console.log("stringData1 =========>"+stringData2.DistrictCode);
>
> console.log("*****ends*******");
> });
>
> app.listen(8889);
> console.log("Server has started.");
>
> client side ajax request is :
> ---------------------------------------
> var inputvalue = {"DistrictCode":"12"};
> $.ajax({
> // url:'http://10.163.14.52:8888/all',
> url:'http://10.163.14.52:8889/getTaluk/',
> type:'POST',
> datatype:'jsonp',
> data:inputValue,
> complete:function(){
> alert("JSON Data Saved Successfully");
> Pouch.destroy('idb://cmcell',
> function(err, info) {
> console.log(JSON.stringify(info));
> this.formClear();
>
> })
> }
> });
>
> And i want to get DistrictCode on server side. So i used that post method
> on server side and used request.body, but it is giving like this
>
> req body:{"{\"DistrictCode\":\"17\"}":""}
>
> How to get the request.body data in proper format.
>
>
>
>
> --
> Thanks,
> N. Srividhya.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.