Pregunta

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'];
¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top