数据没有从ajax发送到php
嗨
在下面的代码中,我想将电子邮件(包含用户输入的数据,如果是电子邮件地址)发送到 php 文件,但
$email = $_POST['email']; <<<<<<<<<<<< this retrieve nothing in the php file
js 文件
<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>
这不会在警报中显示任何内容
hi
in the code below i want to send the email (with input data by user, in case email address) to a php file but
$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>
any reason for that?
i tested email="onePrivateEmail"
in php and the validation is correct, so the problem is the email is not sent by js file. Correct?
thanks
form:
<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>
as i said (before deleted)
<script type="text/javascript">
$(document).ready(function() {
alert( $('#email').val() );
});
</script>
this doesn't show anything in the alert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑到新信息,您没有针对您想要的正确形式
我怀疑您没有加载jquery,或者您确实在输入中放置了任何内容,
这是 demo 在 eamil 中显示数据
your not targeting the right form you want
given the new information I suspect that either you don't have jquery loaded or you did put anything in the inputs
here is a demo showing data in eamil
我会将电子邮件分配给变量和 console.log()。然后将该变量分配给您上面的电子邮件键/值对。可能有助于找出您的问题。请务必检查您的控制台并检查您是否获得了预期的值。
I would assign email to a variable and console.log(). Then assign that variable to the email key/value pair you have above. Might help track down your problem. Be sure to check your console and check you are getting the value you expect.