Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:57:38+00:00 2026-05-24T17:57:38+00:00

The code I am using is working ok but I am a bit stuck

  • 0

The code I am using is working ok but I am a bit stuck at trying to load a new page from a success function. The simplest way to put it is, how do I filter data coming from the php backend to make decisions? for example, I set a condition in the backend testajax.php page and in the ajax success function test for certain conditions. In php it would be something along the lines of using the if statement. I am quite new to jquery so would appreciate some guidance as to how to achieve this. Thanks

$.ajax({
  type: "POST",
  url: "testajax.php",
  data: data,
  success: function (data) {

   $('#login_message').html(data);
   //$(ok).val('Logged In');
   //$("#login").get(0).reset();
   //$("#form").dialog('close');
   $.mobile.changePage( "admin/index.php/", { transition: "slideup"} );
  },
   error:function (xhr, ajaxOptions, thrownError){
   alert('There was an exception thrown somewhere');
   alert(xhr.status);
   alert(thrownError);
  }
});

testajax.php

<?php
  // test wether the user session is already set
  session_start();
  $userpost = mysql_real_escape_string($_POST['user']);

  if (!isset($_SESSION['user'])) {
    $_SESSION['user'] = $userpost;
   if($_SESSION['user']=='admin') {
     echo 'Welcome Admin';
     // for example, test data in ajax for 
     // this flag and if equal 1 then load admin/index.php
     $flag = 'admin';
     // end of flag
     echo $flag;
  }
  else
     echo 'Unknown User';
  }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:57:39+00:00Added an answer on May 24, 2026 at 5:57 pm
    <?php
      // test wether the user session is already set
      session_start();
      $userpost = mysql_real_escape_string($_POST['user']);
    
      if (!isset($_SESSION['user'])) {
        $_SESSION['user'] = $userpost;
       if($_SESSION['user']=='admin') {        
         $flag = 'admin';        
         echo $flag;
      }
      else
         echo 'Unknown User';
      }
    ?>
    

    ajax part

    $.ajax({
      type: "POST",
      url: "testajax.php",
      data: data,
      success: function (data) {
    
       $('#login_message').html(data);
       if(data==='admin')
       { 
        //redirect
        $.mobile.changePage( "admin/index.php/", { transition: "slideup"} );
       }
    
      },
       error:function (xhr, ajaxOptions, thrownError){
       alert('There was an exception thrown somewhere');
       alert(xhr.status);
       alert(thrownError);
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to get an OAuth server working but i'm kinda stuck a bit
I’m trying to get some code working using OData. The following bit of code
I am working on some code using the EMF framework in Java, but it
I have a jQuery code, but need it working by using Mootools: if (
I'using the following code to create thumbnails using ffmpeg but it was working fine
I am new to Python, and I'm working on writing some database code using
I have just been re-working an old bit of compiler-like code written using bison.
I've already got a bit of working code but I need someone to help
I am using the code snippet below, however it's not working quite as I
I am using the below code to block the taskbar which is working perfectly.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.