jquery - PHP header Location admin.php Not redirecting, but the page is downloaded -


console

im trying redirect after successful login, code follows:

//if success (if there row) if ($result->num_rows > 0) { $row = $result->fetch_assoc();     // make server ready session session_start(); $_session['userid'] = $row['user_id']; $_session['first_name'] = $row['first_name']; $_session['user_role'] = $row['user_role']; $_session['status'] = "ok"; session_write_close();   //get user_role proper redirection $iuserrole = $row['user_role']; if($iuserrole==0){  header('location: ../admin.php');   exit(); } else if($iuserrole==1){    header('location: ../user.php');   exit(); } else if($iuserrole==2){    header('location: ../partner.php');    exit(); } 

i can see in browser admin.php downloaded.

the php called with:

$.ajax({         url: 'ajax_api/login_auth.php',         type: 'post',         data: {             "semail": semail,             "spassword": spassword         },     })     .fail(function() {         console.log("jquery ajax login_auth error");     }).success(function(data) {         console.log(data);      }); 

and console.log(data) logs entire html page html/text.

you can not redirect page ajax call. in case need pass url ajax response , redirect page using javascript

php

//if success (if there row) if ($result->num_rows > 0) { $row = $result->fetch_assoc();     // make server ready session session_start(); $_session['userid'] = $row['user_id']; $_session['first_name'] = $row['first_name']; $_session['user_role'] = $row['user_role']; $_session['status'] = "ok"; session_write_close();   //get user_role proper redirection $iuserrole = $row['user_role']; if($iuserrole==0){  echo "{full url}";   exit(); } else if($iuserrole==1){    echo "{full url}";   exit(); } else if($iuserrole==2){    echo "{full url}";    exit(); } 

javascript

// similar behavior http redirect window.location.replace("{url}");  // similar behavior clicking on link window.location.href = "{url}"; 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -