gpt4 book ai didi

php - 使用 $.post 将 JS 变量发送到 PHP 脚本

转载 作者:可可西里 更新时间:2023-11-01 00:14:57 26 4
gpt4 key购买 nike

我正在尝试将 Javascript 变量发送到 PHP 脚本以更新问答游戏的分数。我查找了执行此操作的速记方法,即 $.post,但我无法检索 PHP 脚本中的值。我对哪个 JS 相当陌生,需要帮助了解我做错了什么。

这是Javascript

function updatescore(){
var thisgamemarks= 2300;
var thequizid = 5;
$.post("updatemark.php", { quizidvalue: thequizid, newmarkvalue: thisgamemarks } );
}

还有 PHP

$studentnewmark = $POST['newmarkvalue'];
$thisquizid = $POST['quizidvalue'];
$thisstudentid = $_SESSION['studentid'];

最佳答案

输入 $_POST 而不是 $POST。此外,在基于 Windows 的机器上,您可以使用 ctrl + shift + j 来调试 js 脚本 - 如果您的代码有任何问题,这将有所帮助。但是,您向我们展示的 js 代码看起来非常好。

关于php - 使用 $.post 将 JS 变量发送到 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15452802/

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