javascript - php 无法从 html 中获取值
问题描述
我有疑问,为什么我的 html 文件无法与 php 文件连接。
但我确信在我点击提交按钮后,<input type="hidden" id="t1_response" name="t1_response" value="">
可以给出值。
但是,url 不会更改为 php 形式(如 tocsv.php?t1_response=...)。
php给了我一个通知:
注意:未定义索引:第 2 行 C:\xampp\htdocs\colors\tocsv.php 中的 t1_response
我该如何解决?
<script>
...
function pressSubmit() {
$('#startTrial').hide();
for (var i = 1; i <=3; i++) {
rt = rt + parseFloat(document.getElementById("t"+i+"_rt").value);
};
if (document.getElementById("t1_response").value === "diff") {acc=acc+1};
if (document.getElementById("t2_response").value === "diff") {acc=acc+1};
if (document.getElementById("t3_response").value === "same") {acc=acc+1};
document.write("<div>The average react time: " + rt/3 +" ms</div>");
document.write("<div>Acc Rate:" + acc/3*100+"%</div>");
}
</script>
<style>
...
</style>
<!DOCTYPE html>
<html>
<body>
<h3>Remember the colors</h3>
Press 's' if the two displays are the same. Press 'd' if a color changed (different).<br>
<form action="tocsv.php" method="get">
<input type="hidden" id="t1_response" name="t1_response" value="">
<input type="hidden" id="t1_rt" name="t1_rt" value="">
<input type="submit" id="submitButton" name="submitButton" onclick="javascript:pressSubmit()">
</form>
</body>
</html>
pressSubmit() 包含计算平均数和 document.write() 以向用户显示值。
tocsv.php
<?php
echo $_GET["t1_response"];
?>
解决方案
我已经解决了这些问题。
谢谢大家的帮助。
在这里,在 中pressSubmit()
,我写了doucument.write(...)
,这使得页面被覆盖。因此,结果无法获得价值,我不知道为什么会这样。
因此,我使用alert
以避免覆盖页面。一切正常。
再次感谢大家的帮助!
.
推荐阅读
- sonarqube - 配置 Bamboo 调用 SonarQube 分析基于 Servlet 的 Java 应用程序
- video - 如何使用 ffmpeg 提取和缩放视频?
- java - 如何在 Java 中创建独立的 .exe(无需安装程序和 JRE 即可运行)
- python - 当我通过 SDK 创建工作区包时,如何使我的工作区包的配置状态为“成功”而不是“未完成”?
- azure - Azure 应用程序洞察中的空操作名称(性能菜单)
- javascript - 没有 discord.js 的 Node.JS 命令冷却
- sql - SQL Teradata TOP 和 DISTINCT
- c - Kafka 生产者仅将消息发布到 4 个分区中的一个
- r - 包含带有 R 的日期的平衡面板
- azure-storage - Azure 存储 SAS 无法进行身份验证