简体   繁体   English

将Javascript变量传递给PHP服务器

[英]Passing Javascript Variables to a PHP Server

I'm having some real difficulty with this, I've been searching for hours and hours and I'm having trouble understand. 我在这方面遇到了一些真正的困难,我已经搜索了好几个小时,却难以理解。 I know there are other questions like this but I think I need some context help. 我知道还有其他类似问题,但我认为我需要一些上下文帮助。

The aim is: Everytime a user attempts a quiz, the score they receive will be recorded as a separate record in the attempts table. 目的是:每次用户尝试测验时,他们收到的分数将作为单独的记录记录在尝试表中。

I have the following pages: 我有以下页面:

quiz_form.php, quiz_process.php and quiz.js quiz_form.php,quiz_process.php和quiz.js

The score that I need to pass through to the php, is calculated in the JS file, passed through HTML in results.php and displayed. 我需要传递给php的分数是在JS文件中计算出来的,并在results.php中通过HTML传递并显示出来的。 I need to get this variable, somehow into quiz_process and put it into a table. 我需要以某种方式将这个变量放入quiz_process并将其放入表中。

Quiz_form.php: Quiz_form.php:

<form id="quiz" method="get" class="detailsform" novalidate="novalidate" action="quiz_process.php">

****** QUESTION CODE HERE *****

    <input class="button" type="button" id="chkans" value="Check Answers" />
    <input class="button" type="button" id="submit" value="Submit" />
    <input class="button" type="reset" value="Reset"/>
</form>

quiz.js quiz.js

function sumbit_answers()
{
    store_answers();
    sessionStorage.result = mark_answers();
    alert(sessionStorage.result);
    document.getElementById("result").value = sessionStorage.result;

    alert("You have finished the quiz. Please click OK to go to the results page.");
    window.location.href="quiz_process.php";
}

quiz_process.php quiz_process.php

<?php
require_once("settings.php");

session_start();
$email = $_SESSION["email"];
$result = $_GET["result"];
echo $email; echo $result;

?>

Email is getting through and it's showing but result seems to be very hesitant. 电子邮件正在通过并且正在显示,但结果似乎非常犹豫。 Thank you for any help, I'm sorry for posting but it's 3AM and it's doing my head in. 多谢您的协助,很抱歉张贴,但已是凌晨3点,正全力以赴。

错误与提交按钮有关,它被设置为type =“ button”而不是type =“ submit”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM