dongpochi9741 2015-06-14 08:35 采纳率: 100%
浏览 28
已采纳

使用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?

  • 写回答

2条回答 默认 最新

  • douwang6635 2015-06-14 08:51
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值