www.webdeveloper.com
Results 1 to 4 of 4

Thread: Is it possible to pass php variable to ajax?

  1. #1
    Join Date
    Dec 2012
    Posts
    5

    Is it possible to pass php variable to ajax?

    I try to make redirection after successful login.
    In php if password and user match, then $_SESSION['loggedin'] = 1;
    $ifloggedin = $_SESSION['loggedin'];

    In ajax would need something like this

    if($ifloggedin == 1) {
    window.location = "login-success.php";
    }

    but seems something wrong.

    Could someone explain or give link where I can read about the question?

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,112
    You have to tell the page you want to use PHP:

    if(<?php echo $ifloggedin ?> == 1) {
    window.location = "login-success.php";
    }
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Dec 2012
    Posts
    5
    Thanks for answer, but seems I do not understand
    At the moment I have such code
    HTML Code:
    hr.onreadystatechange = function() {
    if(hr.readyState == 4 && hr.status == 200) {
    var return_data = hr.responseText;
    document.getElementById("status").innerHTML = return_data;
    [B]window.location = "login-success.php";[/B]
    }
    }
    It means in each case when visitor click login button, the visitor is redirected to login-success.php

    What do i need to change/add to get visitor redirected only if php $variable==1; php is in other file....

  4. #4
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,112
    Code:
    <?php
      if ($variable == 1) {
    ?>
    
    hr.onreadystatechange = function() {
    if(hr.readyState == 4 && hr.status == 200) {
    var return_data = hr.responseText;
    document.getElementById("status").innerHTML = return_data;
    window.location = "login-success.php";
    }
    }
    
    <?php
    }
    ?>
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles