Asked  7 Months ago    Answers:  5   Viewed   29 times

i have a jquery Ajax request happening on a page. On php side i am checking if the session is active and doing something. If the session is not active i want to redirect the user to another page in php(header redirect). how do i do it.

I know how to achieve it in javascript(i.e if session_fail then change window.location but is there something that i can do in php/cakephp



If I understand what you want to happen then this is how I'm implementing it. It's in Prototype instead of jQuery but it shouldn't take you long to translate:

new Ajax.Request('process.php', {
    on401: function(response) {
        var redirect = response.getHeader('Location');
        document.location = redirect;

In your PHP, output the following if the session is inactive:

header('Location:', true, 401);
Wednesday, March 31, 2021
answered 7 Months ago

You should check link I refered in comment its your complete answer.

here is a Simple example with your code.

    // Set alerts as array 
$error     = "";

    // I should just trrim and let you check if email is empty .lol 
if (empty($_POST["email_val"])) {
    $error .= "<p class='error'>Fill email value.</p>";

    //Check if this is a real email 
} elseif(!filter_var($_POST["email_val"],FILTER_VALIDATE_EMAIL)){
    $error .= "<p class='error'>Wrong email type.</p>";
    $email = mysqli_real_escape_string($conn, $_POST["email_val"]);

    //You should use prepare statement $email, Shame on you .lol    
    $query = "SELECT * FROM customer WHERE email = '{$email}'");
    $result = mysqli_query($conn, $query);
    echo mysqli_num_rows($result);
    $error .= "ok";
$data = array(
 'error'  => $error

This Jquery :

    var formValues = $(this).serialize();
                if(data.error === 'ok'){
                } else {

And Html :

<form id="myform">
  <input class="input--style-4" id="email" type="email" name="email_val">
  <span id="result"></span>
  <button type="button" class="btn btn-primary">Send</button>
Wednesday, March 31, 2021
answered 7 Months ago

GWT (Google Web Toolkit) is probably the fastest way for a non-UI Java guy to build a complex, ajax-enabled, dynamic UI.

Saturday, May 29, 2021
answered 5 Months ago

You can't match URL's http:// part in Redirect directive. Use this instead:

Redirect 301 /ch-de/Brautschmuck/Schmuckset-Miranda
Saturday, August 21, 2021
answered 2 Months ago

there have been 2 problems in your PHP script:
1. the function was not called
2. the return-value of the function was not echoed.

(in order to respond to an AJAX call, the called url always needs to output something - JSON in the most cases. AJAX can't access PHPand thus can't read PHP return values.)

here is the fixed version:

function update_this_func($remove_option, $uservideo_id){

    global $wpdb;

    $wpdb->query("UPDATE " . $wpdb->prefix."uservideo
                  SET is_removed =" . $remove_option . "
                  WHERE uservideo_id =" . $uservideo_id );

    return json_encode(['status' => 'Updated!']); // return status as json
echo update_this_func($_POST['remove_option'], $_POST['uservideo_id']);
Wednesday, September 1, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :