2013-09-24 3 views
0

Iam new to node.js db에서 데이터를 가져 와서 그 반환 값을 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); 
} 

답변

1

결과는 http.ServerResponse (response 개체)이고 response.end()으로 전화하십시오.

웹 프레임 워크를 사용하고 있습니까? 내 생각 엔 context.resresponse 개체입니다.

사용 :

return context.res.end(JSON.stringify(result)); 

대신

return result; 

참조 :

http://nodejs.org/api/http.html#http_class_http_serverresponse

+0

yessss ... context.res이 object.how 내가 코드를 수정할 수있는 응답이다 네가 말했듯이? – Psl

+0

http : js : 593 throw 새 TypeError ('첫 번째 인수는 문자열 또는 버퍼 여야 함'); – Psl

+0

'result'는'JSON.stringify()'를 사용하는'Object'처럼 보입니다. – leesei