[英]Using $.post to send JS variables to PHP script
I am trying to send Javascript variables over to a PHP script for updating scores of a quiz game. 我正在尝试将Javascript变量发送到PHP脚本以更新测验游戏的分数。 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.
我已经查找了这样做的简写方法,即$ .post,但是我无法检索PHP脚本中的值。 I am fairly unfamiliar which JS and require help as to what I am doing wrong.
我相当不熟悉哪个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'];
type $_POST instead of $POST. 键入$ _POST而不是$ 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.
另外,在基于Windows的机器上,您可以使用ctrl + shift + j来调试js脚本 - 如果您的代码出现任何问题,这将有所帮助。 but, the js code you have shown us looks perfectly fine.
但是,你向我们展示的js代码看起来非常好。
Yes. 是。 As suggest use the $_POST instead of $POST and try putting the "quizidvalue" in the javascript inside quotations.
建议使用$ _POST而不是$ POST,并尝试将“quizidvalue”放在引号内的javascript中。 It might help.
它可能有所帮助。 Just a thought.
只是一个想法。 It's how I always do it.
这就是我一直这样做的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.