Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqueryajax post电子邮件字段_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript jqueryajax post电子邮件字段

Javascript jqueryajax post电子邮件字段,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我不知道为什么我不能发布电子邮件字段的内容 这是我的密码 <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">

我不知道为什么我不能发布电子邮件字段的内容

这是我的密码

<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>

$(文档).ready(函数(){
$(“#提交”)。单击(函数(事件){
var email=$('#email').val();
控制台日志(电子邮件),
$.ajax({
url:'db.php',
键入:“POST”,
数据:“电子邮件=”+“电子邮件”,
成功:功能(数据){
控制台日志(数据);
}
})
});
});
后端文件“db.php”


您正在发送字符串
“电子邮件”
,同时您要发送一个变量值:

$.ajax({
    url: 'db.php',
    type: 'POST',
    data: 'email=' + email, // or data: {email: email}
    success: function (data) {
        console.log(data);
    }
});
用这个会有帮助的


$(文档).ready(函数(){
$(“#提交”)。单击(函数(事件){
var email=$('#email').val();
控制台日志(电子邮件),
$.ajax({
url:'db.php',
键入:“POST”,
数据:{email:email},
成功:功能(数据){
控制台日志(数据);
}
})
});
});

您指的是您的控制台。日志(数据)只返回“电子邮件”吗?如果是这样的话,那是因为你只是在传递“电子邮件”。如果希望ajax返回email.val(),则将var电子邮件传递给ajax,而不仅仅是字符串“email”。
$.ajax({
    url: 'db.php',
    type: 'POST',
    data: 'email=' + email, // or data: {email: email}
    success: function (data) {
        console.log(data);
    }
});