从PHP登录功能获取javascript响应

时间:2014-08-14 06:04:39

标签: javascript php mysql login

public function login($username,$password) {
    $linkingcon = $this->getConnection();
    $sqlquery = "SELECT ac.userID,ac.name,us.usertype FROM users us JOIN accounts ac ON us.userID = ac.userID WHERE us.username='$username' AND us.password='$password';";
    $result = mysql_query($sqlquery , $linkingcon);
    $this->throwMySQLExceptionOnError($linkingcon);
    $row = mysql_fetch_array($result);
    $survey = new stdClass();
    if($row) {
        $res->userID = (int)$row['userID'];
        $res->name = $row['name'];
        $res->usertype = (int)$row['usertype'];
                $string = rand() . 'SurveyLand' . rand() . $username. $password;
            $_SESSION['SURVEYLAND_KEY'] = md5($string);
    } else {
        $res = false;
    }
    return $res;
}

大家好,

即时通讯关于转换的麻烦,我需要通过从另一个脚本(HTML)调用php函数从上面的php函数获得Javascript响应...

P.S 我在互联网上看到了如下的例子,我不能使用下面的方法接听电话

client.sendRequest('hello', null, { 'async': false }, function(rtn) {
    if (rtn.isError()) 
        document.write('<li>Request hello error: ' + rtn.getErrorMessage() + "</li>");
    else
        document.write('<li>Request hello result: ' + rtn.getResult() + "</li>");
});

1 个答案:

答案 0 :(得分:0)

如果您使用json格式的ajax返回响应

return json_encode($res);

或者只是在脚本标记中打印响应

<script>
   var res = <?php echo json_encode(login('username','password')); ?>
</script>