使用$ .post将JS变量发送到PHP脚本 [英] Using $.post to send JS variables to PHP script

查看:211
本文介绍了使用$ .post将JS变量发送到PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Javascript变量发送到PHP脚本以更新测验游戏的分数。我已经查看了执行此操作的速记方法,即$ .post,但无法在PHP脚本中检索值。我不太熟悉哪个JS,需要我做错什么的帮助。

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

Here is the 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代码看起来很好。

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将JS变量发送到PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆