your should move your response handling logic int to the callback of 
reaponseObj. in your current code indexresponseBody is still ""

Am Donnerstag, 5. September 2013 15:59:42 UTC+2 schrieb Amol Pingale:
>
> Hi,
>
> I am using a jquery ajax to call node.js application. In this I am passing 
> JSON data. My node.js is running on 9999 port and my REST web service 
> application is deployed on another server with 8080 port. 
>
> I am calling node.js from my standalone html which has jquery ajax call, 
> from node server.js I am calling REST web service which will return me data 
> populated from database. I am able to print this data on node server.js. 
> After printing this I am setting this to response object and passing it. 
> Below is my code. 
>
> // My stand alone html code which is calling node
> var jsontest = {"key1":"value1","key2":"value2"};
>
> $.ajax({type :"POST",
>                         dataType: 'json',
> data: jsontest,
>                         url: 'http://nodeserverip:9999/sendwelcome',
>                         success: function(data) {
>                             console.log('success');
>                             console.log(data);
>                             console.log(data.id);
>                         }, error : function(response) {
> console.log(JSON.stringify(response));
> }
>                     });
>
> //Node server.js
> var express = require("express"), 
> restapp = require("./testfile.js"), 
> app = express(), 
> http = require("http").createServer(app);
>
> var requestObj = require('request');  
> responseBody = "";
> indexresponseBody = "";
> app.use(express.bodyParser());
>
> //Test call
> app.post('/sendwelcome', function(req, res){
> var tmp = req;
> var tempJSON= JSON.stringify(tmp.body.pubKey).replaceAll('"',"");
> requestObj({
> url : "http://restmoduleip:8080/restmodule/somecontroller/getall";,
> method : "POST",
> headers : { "Content-Type" : "application/json","pubKey":tempJSON},
> body : JSON.stringify(tmp.body)
> },
> function (error, resp, body) {
> indexresponseBody = body;
> }
> ); 
> //Tried using this approach also but response is blank
> // res.header('Content-Type', 'text/html');
> // res.header('Content-Length',indexresponseBody.length);
> // res.send(indexresponseBody);  
> // res.end();
>
> //Tried using this approach also but response is blank
> // res.json(indexresponseBody);  
>
> //Tried using this approach also but response is blank
> res.send(JSON.stringify(indexresponseBody));  
> console.log("RES 1:- "+res);
> res.end();
> console.log("RES :- "+JSON.stringify(res));
> });
>
> I am getting following response in error block of jquery ajax call
> {"readyState":0,"responseText":"","status":0,"statusText":"error"}
>
> Below is response header when I am setting content type and length but 
> response is blank
> Content-Length 988Content-Typetext/html
>
>
> Please let me know what is wrong in it. 
> Thanks in advance.
>
>
>

-- 
-- 
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.

Reply via email to