Iam new to node.js Я хочу получить выборку данных из db и отправить это возвращаемое значение в JQuery. в следующем коде
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
печатает правильные данные, которые я хочу... он становится правильно
В 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);
}
});
внутри этого я не мог получить результирующие данные, возвращаемые с узла, js
success: function (data) {
alert("data-------------"+data);
}
Вы должны написать результат в http.ServerResponse
(объект response
) и вызвать response.end()
.
Используете ли вы какую-либо веб-инфраструктуру? Я предполагаю, что context.res
будет объектом response
.
Использование:
return context.res.end(JSON.stringify(result));
вместо
return result;
Справка:
http://nodejs.org/api/http.html#http_class_http_serverresponse