2014-02-08 55 views
0

我有以下代碼來查找提交表單字段長度的長度。在nodejs中查找表單字段長度

exports.changeStatus = function(req, res) { 
res.header("Access-Control-Allow-Origin", "*"); 
var access_token=req.body.access_token; 
var status=req.body.statuse; 
var access_token_aray=new Array(); 
var respon=""; 
var errorcode=""; 
connection.query('Select `access_token`,`status` from `userss`',function(err,row,field){ 


    if((access_token.length==0)||(status.length==0)){ 
     respon="Please fill all the fields."; 
     errorcode=100; 
    } 

    /*else if(access_token_aray[access_token]!==1){ 
     respon="Invalid access_token"; 
     errorcode=101; 
    } 
    */ 
    if(errorcode){ 
     respon = {"error" : respon, "error-code" : errorcode}; 
    } 
    /* 
    else{ 
     respon = {"log" : 1, "access_token" :access_token }; 
    }  
     */ 
    res.send(JSON.stringify(respon,0,4)); 


}); 

但它給我下面errror

TypeError: Cannot read property 'length' of undefined 
    at Query._callback (/home/group3/www/friends/routes/status.js:23:19) 
    at Query.Sequence.end (/home/group3/www/friends/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24) 
    at Query._handleFinalResultPacket (/home/group3/www/friends/node_modules/mysql/lib/protocol/sequences/Query.js:143:8) 
    at Query.EofPacket (/home/group3/www/friends/node_modules/mysql/lib/protocol/sequences/Query.js:127:8) 
    at Protocol._parsePacket (/home/group3/www/friends/node_modules/mysql/lib/protocol/Protocol.js:197:24) 
    at Parser.write (/home/group3/www/friends/node_modules/mysql/lib/protocol/Parser.js:62:12) 
    at Protocol.write (/home/group3/www/friends/node_modules/mysql/lib/protocol/Protocol.js:37:16) 
    at Socket.ondata (stream.js:51:26) 
    at Socket.EventEmitter.emit (events.js:117:20) 
    at Socket.<anonymous> (_stream_readable.js:720:14) 

回答

0

上面清清楚楚地寫着:

無法讀取未定義

檢查的特性 '長度' 是否你的要求。身體有statuse和access_token像console.log(request.body.statuse).