Reputation: 3920
Iam new to node.js I want to get data fetch from db and send that returned value to Jquery. in the following code
exports.signin = function (signupCollection, context) {
var record = utils.httpBody(context.req);
signupCollection.find({ },{email: record.email,password: record.password},function(err, result) {
console.log("result-------"+result) // prints the data correctly
if(!err) return result;
});
}
result
prints the correct data i want...it is getting properly
In jquery
var data = {
"email": $('#email').val(),
"password": $('#password').val()
};
$.ajax({
type: "post",
url: "/signIn",
dataType: "json",
data: data,
success: function (data) {
console.log("sign in succesfully!!"); // here i want to getthe result data
console.log("SIGN IN RESPOSEE----"+data);
}
});
inside this i couldn’t get the resultant data returned from node,js
success: function (data) {
alert("data-------------"+data);
}
Upvotes: 0
Views: 500
Reputation: 6070
You should have written the result to http.ServerResponse
(response
object) and call response.end()
.
Are you using any web framework? My guess is context.res
would be the response
object.
Use:
return context.res.end(JSON.stringify(result));
instead of
return result;
Reference:
http://nodejs.org/api/http.html#http_class_http_serverresponse
Upvotes: 1