喜
在下面的代码中,我想发送电子邮件(用户输入数据,以防电子邮件地址)到php文件,但
$email = $_POST['email']; <<<<<<<<<<<< this retrieve nothing in the php file
js file
<script type="text/javascript">
$(document).ready(function() {
$("#Form").submit(function() {
$.ajax({
url: "data.php",
type: "post",
dataType: "json",
data: { email: $('#email').val()},
success: function(data) {
if () {
//something
} else {
//something
}
}
});
return false;
});
});
</script>
任何原因?
我在php中测试了email="onePrivateEmail"
并且验证是正确的,所以问题是js文件不发送电子邮件。正确的吗?
感谢
形式:
<form method="post" id="Form" action="">
<div>
<label for="name">Name</label>
<input id="name" name="name" type="text" />
<span id="nameInfo">Insira o seu nome</span>
</div>
<div>
<label for="email">E-mail</label>
<input id="email" name="email" type="text" />
<span id="emailInfo">Insira um email válido por favor!</span>
</div>
<div>
<label for="myPassword">Password</label>
<input id="myPassword" name="myPassword" type="password" />
<span id="myPasswordInfo">Insira pelo menos 4 letras e sem espaços</span>
<div id="bar" style="width: 234px; height: 20px;"></div>
</div>
<div>
<label for="pass2">Confirm Password</label>
<input id="pass2" name="pass2" type="password" />
<span id="pass2Info">Confirme a password</span>
</div>
<div></div>
<div>
<input id="send" name="send" type="submit" value="Send" />
</div>
正如我所说(删除前)
<script type="text/javascript">
$(document).ready(function() {
alert( $('#email').val() );
});
</script>
这不会在警报中显示任何内容
答案 0 :(得分:3)
您没有定位到您想要的正确表单
$("#customForm").submit(function() { ....
鉴于新信息,我怀疑你没有加载jquery或你确实在输入中放了任何东西
这是显示eamil数据的demo
答案 1 :(得分:0)
我会将电子邮件分配给变量和console.log()。然后将该变量分配给您上面的电子邮件键/值对。可能有助于追踪您的问题。请务必检查您的控制台并检查您是否获得了预期的价值。
<script type="text/javascript">
$(document).ready(function() {
var email = $('#email').val();
console.log(email);
$("#Form").submit(function() {
$.ajax({
url: "data.php",
type: "post",
dataType: "json",
data: { email: email},
success: function(data) {
if () {
//something
} else {
//something
}
}
});
return false;
});
});