gpt4 book ai didi

javascript - 输出未定义

转载 作者:行者123 更新时间:2023-12-03 08:23:46 24 4
gpt4 key购买 nike

我正在尝试找到一种方法来注册不同的类(class),您应该在其中输入您的姓名、电子邮件和类(class)的下拉框。该信息应该进入一个 .dat 文件,所有参与者都在其中注册,但不知何故让它们成为未定义的。

<script>
window.onload = startup;

var xmlhttp;

function startup() {
document.getElementById("save").onclick = save;

}

function save() {
var url = "proxy.php?class=" + class + "&name=" + name + "&mail=" + mail;
var class = document.getElementById("class").value;
var name = document.getElementById("name").value;
var mail = document.getElementById("mail").value

xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = status;
xmlhttp.open("GET", url, true);
xmlhttp.send();
}

function status(){
var kurs = document.getElementById("class").value;
if (xmlhttp.readyState ===4 && xmlhttp.status === 200) {
document.getElementById("output").innerHTML = "Signed up for" + kurs;
}
}
</script>
<body>
<input id = "name" type="text" placeholder="Name"></input>
<input id = "mail" type="text" placeholder="Email"></input>
<form action="proxy.php" method="get">
<select id="class">
<option value="812" id="it">SuperIT</option>
<option value="614" id="mh">MH</option>
</select>
</form>
<button id="save" onclick="save()">Sign up</button>
<a href="paameldinger.dat">paamelding.dat</a> // to view the .dat file
<p id="output"></p>

通过如下所示的代理运行它;

<?php

$name = $_GET["name"];
$mail = $_GET["mail"];
$class = $_GET["select"];

$read = fopen("paameldinger.dat", "a");

$line = $class . "¤" . $name . "¤" . $mail . "\n";

fwrite($read,$line);

fclose($read);

?>

输出最终如下所示:

¤undefined¤undefined
¤undefined¤undefined

编辑;有点将代码转换为英语,因为我愚蠢到用挪威语编写代码,所以代码中可能会混合一些挪威语单词,对此感到抱歉!

最佳答案

您在定义变量之前就使用了变量,当然它们都是未定义的。更改您的代码如下:

var class = document.getElementById("class").value;
var name = document.getElementById("name").value;
var mail = document.getElementById("mail").value;

var url = "proxy.php?class=" + class + "&name=" + name + "&mail=" + mail;

关于javascript - 输出未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33640363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com