duanji1056 2013-11-29 22:31
浏览 76
已采纳

如何在用户名重定向页面并通过ajax完成传递请求

I am try to make login system this will check user name and password via php and ajax.i am showing what i have done.

Html

  <div class="container">
  <div id="show-error" style="display:none;" class="alert alert-warning"></div>
  <form  class="form-signin">
    <h2 class="form-signin-heading">Please sign in</h2>
    <input type="text" id="user" class="form-control" placeholder="Email address"  required autofocus>
    <input type="password" id="pass" class="form-control" placeholder="Password"  required>
    <a class="btn btn-lg btn-primary btn-block" onclick="submitfom();" >Sign in</a>

  </form>

JavaScript

function submitfom() {
$.ajax({
          type: "POST",
          url: "checking.php",
          data: {user: $("#user").val(),pass: $("#pass").val()},
       success: function(data){$('#show-error').css("display","inline");$('#show-error').html(data);},
       });
}

PHP

session_start();
include('../../../config.php');
     if((isset($_POST['user'])) && (isset($_POST['pass'])) ){
     $user = $_POST['user'];
     $pass = $_POST['pass'];
     $query = mysql_query("SELECT user FROM admin_user WHERE user ='".$user."' ");
     $query2 = mysql_query("SELECT pass FROM admin_user WHERE pass ='".$pass."' ");

       $result= mysql_num_rows($query);
       $result2= mysql_num_rows($query2);

        if((!empty($result)) && (!empty($result2))){
        $_SESSION['admin']=$user;
      echo "Welcome ". $_SESSION['admin'];
       header('Location: ../../index.php');
        }

        else {echo "Please Write correct <strong>username and password</strong>";}
     }
       else "Some thing miss";

Every thing work fine but now i just need when user write correct username and password than i just need redirection.I am using header location function but actually i am send form values via ajax that's why my redirection not working.i don't know why please help.

  • 写回答

3条回答 默认 最新

  • dourao1896 2013-11-29 22:37
    关注

    Using a location header to redirect will "work". It will tell the browser to get the data for the Ajax response from the new URL.

    If you want to send the user to a new page, then you have to return some data to the browser, detect it, and then set location to a new value with JavaScript.

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

报告相同问题?

悬赏问题

  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式