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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:48:03+00:00 2026-06-08T21:48:03+00:00

I have this button making an ajax call using a click event. My goal

  • 0

I have this button making an ajax call using a click event. My goal is to make it so that the text inside the button changes from “submit” to “loading…” when I make that ajax call. The problem is that for some reason I can’t change the text (or even hide the button) inside of the anonymous function I stick in the .click() method until after all the code is executed. Or at least there is no noticeable effect until the ajax call is completed and instead just sticks in the active state of the button.

I turned async: false in my $.ajax call which is making it take a while to complete everything in the click event. I think I need it this way though for reasons I could go into if necessary. The reason I bring this up is because the solution I’m looking for should change the text before the ajax call in a synchronous fashion.

Here’s a simplified version of the jQuery I’m using:

$('a').click(function(){
    $(this).text('loading');//changing text BEFORE the ajax call
    $.ajax({
        type: 'POST',
        url: 'http://www.jsfiddle.net/',
        data: {foo: 'bar'},
        async: false
    });
    $(this).text('Send Request');
});​

Here’s a jFiddle showing exactly what I mean.

Can I do it this way or do I need to approach this differently?

  • 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-08T21:48:05+00:00Added an answer on June 8, 2026 at 9:48 pm

    EDIT:

    I finally got what you were talking about. Here’s what you can do to have the text change before the ajax starts. Use setTimeout then use the success function to set it back

    $('a').click(function() {
        var $this = $(this);
        $this.text('loading');
        setTimeout(function(){
            $.ajax({
                type: 'POST',
                url: '/echo/json/',
                data: {
                    foo: 'bar',
                  delay: 3
                },
                async: false,           
                success: function(){
                     $this.text('Send Request');  
                }
            });
        },100);      
    });
    

    http://jsfiddle.net/uJzzn/11/

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

Sidebar

Related Questions

I have this function in charge of making a ajax call, and based on
I have this button on the leftside of my UISplitViewController (RootViewController) that has a
So I have this hidden form and this 'I like this' button that I
I have an add this button on the website that is rendering a border
i have this code in the button click to show selection image when the
I have this input text and an input button...I am looking to have them
I have a button with text in it. When clicking this button it will
So, I have a page that looks like the following: alt text http://img704.imageshack.us/img704/5973/croppercapture3.png This
I have this massive nested loop scenario that is calling the DB and making
I have am making a page using Ajax, Jquery, and PHP. I have gotten

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.