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

  • Home
  • SEARCH
  • 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 9201183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:56:40+00:00 2026-06-17T22:56:40+00:00

Possible Duplicate: How to manage a redirect request after a jQuery Ajax call I

  • 0

Possible Duplicate:
How to manage a redirect request after a jQuery Ajax call

I have a form that is validated client-side with Jquery. Jquery then passes this data to a php script for server-side validation. At the end of the php script, I try to redirect upon success, but no re-direction happens.

Is Jquery interfering with the redirection? How can I get the php script to redirect. Don’t want to redirect with jquery, bc I am going to use sessions and want to keep the session data at redirection.

Here is the code:

JQUERY:

$.ajax({
                    //this is the php file that processes the data and send mail
                    url: "includes/process/processAdminLogin.php",
                    //POST method is used
                    type: "POST",
                    //pass the data        
                    data: dataString,    
                    //indicate result is text
                    dataType: "text",
                    //Do not cache the page
                    cache: false,
                    //success
                    success: function (data) {
                        $('input').removeAttr('disabled'); //enable input fields again.

                        if(data == "fail"){
                            $("#statusMessage").html("");
                            $("#statusMessage").html("<p class='statusBoxWarning'>Username and password do not match!</p>");
                            $('button').removeAttr('disabled');
                            document.forms[0].reset();
                        }                               
                    }
                }); 

PHP

if($correctPass == 1){
ob_start();
session_start();
$_SESSION['usernameIdentity'] = $userName;
unset($userName, $userPass);
header("Location: ../../adminDashboard.html");
exit;
}else{
echo "fail";
}

The php script gets to the redirection part and just hangs up. I would really want to keep jquery functionality, along with php redirection. Is there a better method?

Thanks!

                              FINAL WORKING SOLUTION:

Ok, after the input from this post and other similar posts, this is what I have as the working solution. It may not be the most efficient or prettiest solution, but it works, and will have to do for now.

JQUERY

$.ajax({
                    //this is the php file that processes the data and send mail
                    url: "includes/process/processAdminLogin.php",
                    //GET method is used
                    type: "POST",
                    //pass the data        
                    data: dataString,    
                    //indicate result is text
                    dataType: "text",
                    //Do not cache the page
                    cache: false,
                    //success
                    success: function (data) {
                        $('input').removeAttr('disabled'); //enable input fields again.
                        if(data == "success"){
                            $('#statusMessage').html('<form action="http://www.example.com/test/userRegistration/adminDashboard.html" name="userSubscription" method="post" style="display:none;"><input type="text" name="username" value="' + reg_contact_username + '" /><input type="text" name="password" value="' + reg_contact_password + '" /></form>');
                            document.forms['userSubscription'].submit();
                        }else{alert("couldn t redirect");}                              

                    }
                }); 

PHP

if($correctPass == 1){
echo "success";
}else{
echo "fail";
}

The receiving redirection page will have to verify username and password being given again, so validation will be done 2x…which is really inefficient. If anybody can provide me with a better solution – please! A sample write out would also help out.

Thanks!

  • 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-06-17T22:56:42+00:00Added an answer on June 17, 2026 at 10:56 pm

    Since AJAX happens “behind the scenes” (so to speak) your redirect will just interrupt the response to your javascript handler.

    You’ll need to return the URL and have your callback kick the browser to a new location.

    Update:

    On this note, since you have to return data to the front end, you’ll want to add a status or similar variable so that you can switch your front end behavior based on whether the call “failed” or not.

    Update 2:

    In response to your solution, I strongly recommend against your form submission technique. As you say, it’s not efficient, it’s not pretty, and it requires twice the work (validating the user 2 times).

    Why don’t you use PHP’s built in session handling to set a session if the user logs in successfully, and then simply check the session after a simple javascript browser redirect?

    A javascript redirect is as simple as window.href = "http://mylocation" and if you don’t know much about PHP’s sessions, you could use this class I’ve built up (please disregard that it’s also managing cookies, that’s a silly oversight).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Checking for an SQL result in VB.NET I have login form which
Possible Duplicate: jquery select iframe children I have many frames in my asp.net website.
Possible Duplicate: How to automatically start your service after install? I have a Visual
Possible Duplicate: C# 4.0 unlock image after creating BitmapImage I have this code to
Possible Duplicate: using statement with multiple variables I have several disposable object to manage.
Possible Duplicate: Caching readdir() I have my site set up so that I have
Possible Duplicate: Managing large binary files with git The situation is that I have
Possible Duplicate: How can I get drop down menu value still selected after form
Possible Duplicate: jQuery and pseudo-classes I tried hiding the :after pseudo class via jQuery
Possible Duplicate: How to manage your remote desktop Now that I'm building a site

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.