$ .ajax并没有弄清楚为什么PHP没有从$ .ajax调用接收POST数据

时间:2017-03-17 05:50:28

标签: javascript php jquery ajax

$ .ajax成功了,但在php中,我无法从ajax获取数据。

  

注意:未定义的索引:电子邮件在..

     

注意:未定义的索引:传入..

$(document).ready(function(){
 $(document).on('click',"#bolero-user-login",function(){
     var email = $("#edit-name").val();
     var pass  = $("#edit-pass").val();
     // alert (email);
     $.ajax({
        url:"functions/php/login.php",
        type:"POST",
        data:{ "email":email,"pass":pass},
        beforeSend: function () {

        },
        success:function(){
            alert("success");
            alert(email);
            $("#edit-name").val(" ");
            $("#edit-pass").val(" ");
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
             alert(XMLHttpRequest.status);
             alert(XMLHttpRequest.readyState);
             alert(textStatus);
        },
     });
     return false;
 });

});

PHP:

<?php

define ("root",$_SERVER['DOCUMENT_ROOT']);
// echo root;
include root.'/maroon5/includes/dbh.php';
print_r($_REQUEST);

$email = $_POST['email'];
$pwd = $_POST['pass'];

?>

这是来自firefox的图片

Image

Image

ajax success picture PHP console picture

1 个答案:

答案 0 :(得分:0)

将AJAX成功转变为

success:function(data){             
    console.log(data);
    $("#edit-name").val(" ");
    $("#edit-pass").val(" ");
},

和AJAX页面一样

<?php

define ("root",$_SERVER['DOCUMENT_ROOT']);
// echo root;
include root.'/maroon5/includes/dbh.php';
// print_r($_REQUEST);

$returnArr['email'] = $email;
$returnArr['pwd'] = $pwd;

echo  json_encode($returnArr);

?>