我在服务器 1 上创建变量,然后使用位于服务器 2 上的 PHP 文件通过 post 将它们发送到服务器 2 上的 mySQL 数据库。
服务器 1 上的 JavaScript...
$.post( "http://www.website.com/xxx/update.php", { vote:currentVote, page:currentmatch, round:roundNumber, team1: firstTeam, team2: secondTeam });
PHP 接收帖子,位于服务器 2...
$round = $_POST['round'];
//etc...
//I then set the query and insert the data, no problem.
之后,在同一个 PHP 文件上,计算行数并将总计分配给变量...
$result = $connection->query("SELECT * FROM {$page} WHERE 'vote' = {$team1}")) {
$team1Count = $result->num_rows;
}
如何将更新后的 $team1Count 变量发送回原始页面?
谢谢!
最佳答案
jQuery 的 .post()
具有回调功能,您可以将其作为参数提供。
$.post( "http://www.website.com/xxx/update.php", {
vote:currentVote,
page:currentmatch,
round:roundNumber,
team1: firstTeam,
team2: secondTeam },
function(data){
//the call back, data contains your return from your php script
console.log(data);
});
只需从您的 php 脚本中回显该变量即可
echo $team1Count;
关于javascript - 将变量从 .js 传递到 PHP,然后接收新的 var 作为响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22340909/