gpt4 book ai didi

javascript - 从 PHP 登录函数获取 javascript 响应

转载 作者:行者123 更新时间:2023-11-29 23:56:28 26 4
gpt4 key购买 nike

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 响应...

附注我在互联网上看到了一个例子,如下所示,我不能使用如下方法来接听电话

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>");
});

最佳答案

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

return json_encode($res);

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

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

关于javascript - 从 PHP 登录函数获取 javascript 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25301083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com