سؤال

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.

Here is the Javascript

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

And the PHP

$studentnewmark = $POST['newmarkvalue'];
$thisquizid = $POST['quizidvalue'];
$thisstudentid = $_SESSION['studentid'];
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top