【发布时间】:2018-12-15 19:26:39
【问题描述】:
我想在 POST 中使用 php 脚本从我的 html 表单中获取一些数据,但是这个脚本是在 javascript 脚本中调用的,当我尝试获取数据时出现以下错误:“未定义索引”
谁能帮帮我?对不起,我刚刚开始学习 PHP
部分 HTML:
<form class="form" id="myform" method="post">
<div class="form__group">
<input type="text" placeholder="Username" id="Username" name="Username" class="form__input" />
</div>
</form>
部分JS脚本:
if (errors == false) {
var Username = document.getElementById("Username");
var Password = document.getElementById("Password");
$.ajax({
url: "scripts/register.php",
success: function () {
alert('Success');
}
});
部分 PHP 脚本:
$Username = $_POST['Username'];
$Password = $_POST['Password'];
【问题讨论】:
-
建议您先阅读 $.ajax 文档以设置
data和method -
什么是确切的错误,无法注意到表单中的密码字段。
-
@charlietfl 抱歉,我听不懂……我该怎么办?
-
您没有指定要发送哪些数据,或者应该通过什么方法发送。
-
您必须将数据发送给
$_POST才能读取,并且您需要将方法设置为POST。也建议学习一些ajax/php教程
标签: javascript php ajax post indexing