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 7415007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:12:49+00:00 2026-05-29T07:12:49+00:00

I’m trying to create a pop up box (with jQuery) that can handle forms,

  • 0

I’m trying to create a pop up box (with jQuery) that can handle forms, and for the most part, I have it all working. The only issue that I have is that on a successful login and/or register, PHP sends a header location to redirect to the user to their “home”, and it creates an endless loop of redirects with in the div that I loaded the form.

How would I go about reading if there was a location header sent on the post request, and then to get the actual URL that is being sent as the new location?

This is what I have tried so far (among other things):

$('.register').live('submit', function(e) {

    e.preventDefault();

    var form_data = $(this).serialize() + '&register=register&js=true';

    $.post(site_path + '/register', form_data, function(data, text, xhr) {

        alert(xhr.getResponseHeader("Location"));

        // $('.overlay_container').html(data);

    });

});

Not sure what exactly I’m doing wrong, but as far as I know, something along those lines should work. I also tried doing this with a plain AJAX post request to no expected result.

Just to note, there wont always be a location header sent; only when someone successfully logs in, registers, etc.

Ideally, this is what I am trying to accomplish:

$('.register').live('submit', function(e) {

    e.preventDefault();

    var form_data = $(this).serialize() + '&register=register&js=true';

    $.post(site_path + '/register', form_data, function(data, text, xhr) {

        var header_location = xhr.getResponseHeader("Location");

        if(header_location == null) {

            $('.overlay_container').html(data);

        }else{

            window.location = header_location;

        }

    });

});
  • 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-29T07:12:50+00:00Added an answer on May 29, 2026 at 7:12 am

    As far a I am aware, you can not actually read a Location header as JavaScript follows it until they stop, and then sends the headers back, meaning that I get the headers of the destination page, and not the page that was initially posted to.

    Therefore, I have edited my redirect function that I have in my PHP script to send a custom header if the page was requested using JavaScript (or jQuery).

    public function redirect($redirect = NULL) {
    
        global $_CONFIG;
    
        if($_POST['js'] == 'true') {
    
            exit(header('Redirect: ' . $_CONFIG['site']['path'] . '/' . $redirect));
    
        }else{
    
            exit(header('Location: ' . $_CONFIG['site']['path'] . '/' . $redirect));
    
        }
    
    }
    

    That way I can read if the a redirect was actually sent, and handle it properly on the JavaScript (jQuery) end of things.

    Here’s what the final result looks like:

    $('.popup').on('submit', '.register', function(e) {
    
        e.preventDefault();
    
        var action = $(this).attr('action'), form_data = $(this).serialize() + '&register=register&js=true';
    
        $.post(action, form_data, function(data, text, xhr) {
    
            var header_location = xhr.getResponseHeader('Redirect');
    
            if(header_location == null) {
    
                $('.overlay_container').html(data);
    
            }else{
    
                window.location = header_location;
    
            }
    
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.