jQuery ajax发布电子邮件字段 [英] jquery ajax post email field

查看:103
本文介绍了jQuery ajax发布电子邮件字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么我不能发布电子邮件字段的内容,

I'm not sure why I'm not able to post the content of email field,

这是我的代码.

<html>
<head>
    <title></title>
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>
    <input type="text" id="email" name="email">
    <input type="button" id="submit" name="submit" value="submit">
</body>

<script type="text/javascript">

$(document).ready(function () {

    $('#submit').click(function (event) {
        var email = $('#email').val();
        console.log(email),
        $.ajax({
            url: 'db.php',
            type: 'POST',
            data: 'email=' + 'email',
            success: function (data) {
                console.log(data);
            }
        })
    });

});

</script>
</html>

后端文件"db.php"

backend file "db.php"

 <?php  
 $email = $_POST['email'];
 echo "$email";

在能够将电子邮件提交到db.php之前,我能够对其进行console.log电子邮件并正确显示.

I'm able to console.log email, and displays correctly, before it gets submitted to db.php.

控制台日志仅返回电子邮件".

console log returns "email" only.

不确定发生了什么问题,我们非常感谢您的帮助.

Not sure whats wrong, your help is highly appreciated.

谢谢

推荐答案

您要发送字符串"email",而您要发送变量值:

You are sending string "email", while you want to send a variable value:

$.ajax({
    url: 'db.php',
    type: 'POST',
    data: 'email=' + email, // or data: {email: email}
    success: function (data) {
        console.log(data);
    }
});

这篇关于jQuery ajax发布电子邮件字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆