クライアント側でhtmlを使用しており、サーバー側のコードはnode.jsにあります。nodejsアプリケーションに定義されたいくつかのURLがあり、クライアントhtmlファイルからそれらを呼び出しています。ノードから、別のサーバーにある REST アプリケーションを呼び出しています。この REST アプリケーションは、Jersey Java Web サービスで記述されています。私はhtmlからnode.jsを呼び出すことができ、ノードコードからJersey Webサービスモジュールから応答を得ています。この応答を受け取った後、node.js の応答オブジェクトに設定していますが、この応答は html jquery ajax 呼び出しでは利用できません。
$.ajax({
type :"POST",
dataType: 'json',
data: jsontest,
url: 'http://<code>localhost</code>:9999/hello',
success: function(data) {
console.log('success');
console.log(data);
console.log(data.id);
}, error : function(response) {
console.log(JSON.stringify(response));
}
});
サーバー側のコード:
var tmp = req;
var authentication = JSON.stringify(tmp.body.authenticationKey);
console.log("authentication :- "+authentication);
requestObj({
url : "http://<code>restserver</code>:port/restmodule/controller/hello",
method : "POST",
headers : { "Content-Type" : "application/json","pubKey":authentication},
body : JSON.stringify(tmp.body)
},
function (error, res, body) {
indexresponseBody = JSON.stringify(JSON.parse(body).message);
}
);
res.writeHead(200, {'content-type':'text/html'});
console.log("JSON returned from REST "+indexresponseBody);
res.write(indexresponseBody);
res.end();
json を取得できました。これはノード サーバー コンソールに出力されます。しかし、この json を firebug コンソールの response(res) オブジェクトに書き込んでいるときに、この json を見ることができません。この応答を取得する方法を誰か教えてください。