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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:41:19+00:00 2026-05-20T09:41:19+00:00

I’m working on an app and trying to use the Facebook behavior for an

  • 0

I’m working on an app and trying to use the Facebook behavior for an AJAX request. In Facebook you get a nice loading image next to the icon which triggers the AJAX request. Well, it’s pretty simple to implement if you have 1-2 elements in the page.

I want to make it generic and would like that whenever any element triggers an AJAX request, I want to show a small GIF next to it. For this, I thought the AjaxSend event of jQuery would be good enough, but alas it doesn’t give me a handle of the object which triggered the AJAX call. I would like to know if it is possible via some method of jQuery to know which element triggered the AJAX call and also to get the same handle when the AJAX call is completed.

If you feel my approach to the problem is not correct, I would love to hear your suggestions.

  • 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-20T09:41:20+00:00Added an answer on May 20, 2026 at 9:41 am

    If you want to use the ajax request handlers, an id will need to be assigned (manually or automatically) to the element that triggered the event. You could then send this id as an additional key-value pair in the request (element_id:THEID) and grab it with various substring methods in the ajax request handlers.

    Example:

    <script type="text/javascript">
    
        $(document).ready(function(){
    
            $("input").click(function(){
    
                var newid = (create a custom id with date and time);
    
                $(this).attr("id", newid);
                $.post("handler.php", {element_id : $(this).attr("id")});
            });
    
       }).ajaxSend(function(e, xhr, settings){
    
            var start_position = settings.data.indexOf("element_id");
            var equalsign_position = settings.data.indexOf("=", start_position);
            var ampersand_position = settings.data.indexOf("&", start_position);
    
            var element_id;
            if(ampersand_position == -1){
                element_id = settings.data.substr(equalsign_position+1);
            } else {
                element_id = settings.data.substr(equalsign_position+1, ampersand_position-equalsign_position-1);
            }
    
            $("#"+element_id).after("<div id='div"+element_id+"'><img src='loading_start.png' /></div>");
    
        }).ajaxComplete(function(e, xhr, settings) {
    
            var start_position = settings.data.indexOf("element_id");
            var equalsign_position = settings.data.indexOf("=", start_position);
            var ampersand_position = settings.data.indexOf("&", start_position);
    
            var element_id;
            if(ampersand_position == -1){
                element_id = settings.data.substr(equalsign_position+1);
            } else {
                element_id = settings.data.substr(equalsign_position+1, ampersand_position-equalsign_position-1);
            }
    
            $("#div"+element_id).remove();
    
    
        });
    
        </script>
    
        <input type="button" value="Save" />
    

    The alternative is handling the appearing and disappearing of the loading image in each event handler (but I seem to understand you have too many of them?), like this:

    <script type="text/javascript">
    
        $(document).ready(function(){
    
            $("input").click(function(){
    
    
                var element_id = (generate custom id);
    
                $(this).after("<div id='div"+element_id+"'><img src='loading_start.png' /></div>");
    
                $.post("handler.php", {var:"hello"}, function(){
                    $("#div"+element_id).remove();
                });
    
            });
        })
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.