1

At my page when a user click any book name from list, it will be send data a php query and after query that book page will be open at browser.

Now after php process it cannot redirect any book page. I tryed also redirect with echo("<script>location.href = 'http://myweb.com/$user';</script>"); and ob_start(); at top, But not work also. There is no blank space before & after php and have no error log also. Chrome network tools display sent data well to testpage.php and also open that book's page there. But browser dose not redirect at any page.

This is page button:

<a href="javascript: void(0)" id="'.$mypage.'" class="user">  '.$mypage.'</a>

JS script:

$(document).on('click', 'a.user', function(e){
    var getID   =  $(this).attr('id');
    $.post("../testpage.php?user=" + getID, function(){
    });
});

Testpage.php

<?php
error_reporting(E_ALL);
require('db.php');
if($_REQUEST['user'])
    {
    global $db;
    $user=$_REQUEST['user'];
    //others all process
    header("location: http://myweb.com/$user");
    exit;
    }
?>

1 Answer 1

3

testpage.php is called by your AJAX request and that's the request that will get redirected. In order to redirect the main page (the one that is sending the AJAX request), you'll need to do the redirect in javascript in the callback called after successful AJAX call:

$(document).on('click', 'a.user', function(e){
  var getID =  $(this).attr('id');
  $.post("../testpage.php?user=" + getID, function(){
    window.location = 'http://myweb.com/' + getID;
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

All my books have not same location. So I was avoiding to do it. Trying now.
You can always return some data from testpage.php and use that data to do the redirect to correct URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.