0
Iam new to node.js 我想從數據獲取數據庫並將返回的值發送到Jquery。 下面的代碼發送從node.js到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);
}
yessss ... context.res是object.how我可以修改代碼的響應像你說的? – Psl
正在獲取http.js:593 throw new TypeError('第一個參數必須是字符串或緩衝區'); – Psl
'result'似乎是一個'Object',使用'JSON.stringify()'。 – leesei