0

I don't know where is the problem.I try to pass the email and password to the php page,but it always"undefined index email.."''the index page is alright,but the php page can not receive any data from ajax,I have never seen situation like this. index page :

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
    $(document).on('click',"#bolero-user-login",function(){
     var email = $("#edit-name").val();
     var pass  = $("#edit-pass").val();

     $.ajax({
        url:"login.php",
        type:"POST",
        data:{ "email":email,"pass":pass},

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

});
</script>
</head>
<body>

<form id="userid"  class="user-login-id" >
    <div style="height: 204px;">
    <div class="form-name form-it">
        <label for="edit-name" >E-mail Address
             <span >*</span> <br/></label>
             <input id="edit-name"  type="text" name="email" />
        </div>
        <div class="form-pass form-it" id="it">
            <label for="edit-pass">Password<span  >*</span><br/> </label>
             <input id="edit-pass"  type="text" name="pass"   />
        </div>
        <div class="form-ac">
            <input id="bolero-user-login" type="submit"  value="Login" >
        </div>
    </div>
</form>
</body>
</html>

PHP page:

<?php
//
//

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

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

//echo "$email";
?>

index page

php page

L Tulip
  • 59
  • 9
  • can u post your html please – Masivuye Cokile Mar 17 '17 at 08:41
  • 1
    According to the alert and browser debugging tools in that screen shot, your PHP isn't executing at all. – David Mar 17 '17 at 08:44
  • @MasivuyeCokile ,you can scroll down ,the html code is after jquery – L Tulip Mar 17 '17 at 08:46
  • Yes @David I think that too.. It seems that `short_open_tags` is not enabled .. try changing `` to ` – Mihai Matei Mar 17 '17 at 08:46
  • @LTulip I just copied and paste your code and is working well, the alert does show the results of var_dump – Masivuye Cokile Mar 17 '17 at 08:47
  • the problem is with your db config can u paste that as well? `dbh.php` – Masivuye Cokile Mar 17 '17 at 08:48
  • @MateiMihai ,I delete these `define ("root",$_SERVER['DOCUMENT_ROOT']); // echo root; include root.'/maroon5/includes/dbh.php'; var_dump($_REQUEST);` but it still the same error – L Tulip Mar 17 '17 at 08:49
  • @MasivuyeCokile I delete these db fonfig file ,just leave three lines code ` ` Still the same error "undefined index email..." – L Tulip Mar 17 '17 at 09:03
  • @LTulip add `dataType: 'json'` to your ajax options. Also, please note that the response of the PHP file should be in json format: `echo json_encode(array('test' => 'test'));`. In the success callback you will be able to use `data.test` as you wish – Mihai Matei Mar 17 '17 at 09:10

0 Answers0