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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:47:39+00:00 2026-06-14T00:47:39+00:00

When a user clicks a certain link, I’d like to run an AJAX call

  • 0

When a user clicks a certain link, I’d like to run an AJAX call that sets a $_SESSION variable, while still directing the user towards the link’s href.

When I run the following code, Firebug shows that there is an error, but doesn’t specify; readyState=0, status=0, statusText="error" is all I get from console.log.

If I add e.preventDefault and window.location.href = linkPath; into my success function, the script sends the user to the correct place; but only after a delay while it waits for the php page to complete.

How can I run the AJAX call while still passing the user through to their link without delay?

$(document).ready(function() {
$(".example_class").click(function(e) {
    //Stop the page from leaving until we start our ajax
    //e.preventDefault();

    //var linkPath = this.href;

    var form_data = new Object();

    //Set the application ID for insert into the DB
    form_data.variableName = encodeURIComponent('ExampleName');

    //Send the data out to be processed and stored
    $.ajax({
       url:'/mypath/myfile.php',
       type:'POST',
       data:form_data,
       success:function(return_data){
            //window.location.href = linkPath;
            return;
        },
       error:function(w,t,f){
           console.log(w);
           return;
       }
    }); 

    return;
});
});
  • 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-14T00:47:40+00:00Added an answer on June 14, 2026 at 12:47 am

    As said in coments, ajax calls are aborted when the caller page is unloaded.
    But it does not mean that the server has not received the call, it only means that the server has not sent back a reply.
    To minimize the time spent by the ajax call, you could just wait for the first response to the ajax call with “xhr.onprogress” (which is not implemented in $.ajax from jquery), and then open the link.

    But, if you were having the control of the server, simply make a redirection of ‘/mypath/myfile.php?redirect_url=’+linkPath to linkPath with:

    header('location: '.$_GET['redirect_url']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user clicks a certain link which contains an image that should be
In my app a user clicks a link to another page. I'd like to
I have some code that when a user clicks on a link Add Comment,
I am relatively new to Javascript/Ajax. When the user clicks on certain urls, I
When a user clicks a table row, I use jQuery to select the link
Use case: user clicks the link on a webpage - boom! load of files
I have an IFrame that has dynamic content depending on what link a user
I've created an account verification system where a user clicks a link in their
I have some javascript on a view that makes an ajax call to my
I am trying to get the user to a certain URL when he clicks

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.