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

时间:2022-06-05 01:11:33

I am trying to send Javascript variables over to a PHP script for updating scores of a quiz game. I've looked up the shorthand method of doing this, which is $.post, but I am unable to retrieve the values in the PHP script. I am fairly unfamiliar which JS and require help as to what I am doing wrong.

我正在尝试将Javascript变量发送到PHP脚本以更新测验游戏的分数。我已经查找了这样做的简写方法,即$ .post,但我无法检索PHP脚本中的值。我很不熟悉哪个JS并且需要帮助我做错了什么。

Here is the Javascript

这是Javascript

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

And the PHP

还有PHP

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

2 个解决方案

#1


8  

type $_POST instead of $POST. also, on a windows based machine, you can use ctrl + shift + j to debug a js script - which will help if if there's any problems with your code. but, the js code you have shown us looks perfectly fine.

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

#2


0  

Yes. As suggest use the $_POST instead of $POST and try putting the "quizidvalue" in the javascript inside quotations. It might help. Just a thought. It's how I always do it.

是。建议使用$ _POST而不是$ POST,并尝试将“quizidvalue”放在引号内的javascript中。它可能有所帮助。只是一个想法。这就是我一直这样做的方式。

#1


8  

type $_POST instead of $POST. also, on a windows based machine, you can use ctrl + shift + j to debug a js script - which will help if if there's any problems with your code. but, the js code you have shown us looks perfectly fine.

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

#2


0  

Yes. As suggest use the $_POST instead of $POST and try putting the "quizidvalue" in the javascript inside quotations. It might help. Just a thought. It's how I always do it.

是。建议使用$ _POST而不是$ POST,并尝试将“quizidvalue”放在引号内的javascript中。它可能有所帮助。只是一个想法。这就是我一直这样做的方式。