数据没有从ajax发送到php

发布于 2024-11-01 08:01:24 字数 2862 浏览 1 评论 0原文


在下面的代码中,我想将电子邮件(包含用户输入的数据,如果是电子邮件地址)发送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-11-08 08:01:24

考虑到新信息,您没有针对您想要的正确形式

 $("#customForm").submit(function() { ....

我怀疑您没有加载jquery,或者您确实在输入中放置了任何内容,

这是 demo 在 eamil 中显示数据

your not targeting the right form you want

 $("#customForm").submit(function() { ....

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

绝不放开 2024-11-08 08:01:24

我会将电子邮件分配给变量和 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;
     });
});

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.

<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;
     });
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文