使用Ajax的php头转发问题

Form:-

  <form  name="form"> 
                    <div class="formfieldContainer">
                        <label> Email :</label>
                                                      <div class="login_wrapper loginContainer">
                                                          <span> </span>
                                                        <input type="email" id="email" required name="user_email" autofocus="autofocus" placeholder="Enter Email Address"/>
                                                    </div>
                                            </div>
                    <div class="formfieldContainer">
                        <label> Password :</label>
                        <input type="password" name="user_password" placeholder="Enter Password"/>
                    </div>

                    <input type="button" name= "submit" value="submit" id="submit_login"/>

                </form>

AJAX:-

$("#submit_login").click(function(){
       var username=$('input[name=user_email]').val();
       var password=$('input[name=user_password]').val();        

         $.ajax({
                type: "POST",                    
                url: "newExam.php", 
                data:{name: username,
                       pwd: password},
                       cache: false,                          
                success: function(dataa) {
                   if(dataa)
                   {
                       console.log(dataa);   
                      if(dataa==0)
                      {  $('form').effect( "shake" ); $('p.error').show(); $("#submit_login").val('Login')
                       alert('nodata');
                       }


                    else if(dataa==1){
                    window.location.href="user.php";
                        }
                     }
                 }
              });// ajax
});

PHP:-

<?php  
include('db.php');
$email_php = $_POST['name'];  
 $pwd_php=$_POST['pwd'];
 $sql = "select name from user where email='$email_php' and  password='$pwd_php'";  
$result = mysqli_query($conn,$sql);  
 $num_rows=  mysqli_num_rows($result);
if($num_rows>0){     
   $_SESSION['login_user']= $email_php;       
   echo '1';
 }
 else{  
echo '0';
  }
  ?>

I need the page to redirect to user.php when logged in successfully. But i am getting the following error:

Notice: Undefined index: name in C:\xampp\htdocs\demo
ewExam.php on line 3

Notice: Undefined index: pwd in C:\xampp\htdocs\demo
ewExam.php on line 4

How to overcome it?

Yo should be redirecting it from php page (using headers)instead of using window.location.href

You can use this method if you don't want to use php.

$.extend( {
    redirectPost: function(location, args)
    {
        var form = '';
        $.each( args, function( key, value ) {
            form += '<input type="hidden" name="'+key+'" value="'+value+'">';
        });
        $('<form action="'+location+'" method="POST">'+form+'</form>').submit();
    } });

Usage

$.redirectPost("user.php", {'key1': 'data1', 'key2': 'data2'});

Credit - https://gist.github.com/aabril/e6b96379ab0eb151a179