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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:30:46+00:00 2026-05-25T21:30:46+00:00

My setup is like this (simplified for clarity) : <div class=methods> <a href=#a>Method 1</a>

  • 0

My setup is like this (simplified for clarity) :

<div class="methods">
    <a href="#a">Method 1</a>
    <a href="#b" class="fb_method">FB Method</a>
    <a href="#c">Method 3</a>
</div>

... <!-- contents -->

So each method, if clicked, will fade in the inline contents, except anchor that has “fb_method” class, since it needs to do an AJAX request first before appending to its content container in the contents.

So my jQuery is like this :

$('.methods a').click(function(){
    // do something global to the anchors, eg : change the bg color, etc
    // set the target container
    var target = $(this).attr('href');
    var xhr;

    //if user clicks fb_method buttons
    if($(this).hasClass('fb_method')){
        //do ajax request - NOTE 1
        xhr = $.post("/ajax/get_fb_albums.php",function(msg){                           
            $(target).html('').append(msg).fadeIn();
        });
    }else{
        //abort all ajax request
        xhr.abort();
        $(target).fadeIn();
    }
    return false;
});

So what I want is when users first click fb_method button, it will request an AJAX. But if they suddenly change their mind and click other methods, I want to abort the previous AJAX request.

I tracked it via Firebug and it returns an error of the xhr being undefined. if I moved the xhr in NOTE 1 before the if statement, it works but the AJAX request is still being processed. What I mean is in Firebug when I click the FB method then click other methods, it displayed something like this:

// ajax request xhr - keeps on loading
// ajax request xhr aborted

But the request keeps on loading.

  • 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-25T21:30:46+00:00Added an answer on May 25, 2026 at 9:30 pm

    Your xhr variable is local inside the function called when the click event happens.

    When you call the abort method, xhr is not the variable used for the post method.

    The xhr variable needs to be external to the function binded to the click event, otherwise it will be undefined when you check it for other click events.

    Additionally, since you probably need more than one xhr variable to store different post, you should create an array or an object to store the different post.

    var xhr = [];
    
    $('.methods a').click(function(){
        // do something global to the anchors, eg : change the bg color, etc
        // set the target container
        var target = $(this).attr('href');
    
        //if user clicks fb_method buttons
        if($(this).hasClass('fb_method')){
            //do ajax request (add the post handle to the xhr array)
            xhr.push( $.post("/ajax/get_fb_albums.php", function(msg) {                           
                $(target).html('').append(msg).fadeIn();
            }) );
        }else{
            //abort ALL ajax request
            for ( var x = 0; x < xhr.length; x++ )
            {
                xhr[x].abort();
            }
            $(target).fadeIn();
        }
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table setup like this (simplified for example): user_id item_id click_dt Each
I have a setup like this: <div id=container> <div id=close>Close</div> </div> Then in my
If I have a simple class setup like this: class MyClass { private string
I have a page that is setup like this public partial class _Default :
So I have a database that is setup sort of like this (simplified, and
i have a panel setup like this(each number represents a panel): 1 2 3
I want a setup like this: +- /ApplicationFolder -- App.exe -- Core.dll -- AnotherShared.dll
I have a Drupal setup like this: Content type: Apartments Vocabulary: Areas , that
I have a ToggleButtonBar with a DataProvider setup like this: <mx:ToggleButtonBar itemClick=clickHandler(event); selectedIndex=0> <mx:dataProvider>
I'm using a ListView that is setup like this: <ListView android:id=@android:id/list android:layout_width=fill_parent android:layout_height=fill_parent android:longClickable=false

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.