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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:42:11+00:00 2026-05-19T01:42:11+00:00

I have this code: $(‘#page-refresh’).click( function() { $.ajax({ url: /page1.php, cache: false, dataType: html,

  • 0

I have this code:

   $('#page-refresh').click( function() {
        $.ajax({
            url: "/page1.php",
            cache: false,
            dataType: "html",
            success: function(data) {
                $('#pagelist').html(data);
            }
        });
         return false;
   });

In this code is it possible that on the ajax success function it disables the #page-refresh click for 5 seconds then re-enable it? Basically if a person clicks the button and this action happens I dont want them to click and run this action again for another 5 seconds. I looked at delay() to unbind the click for this then bind it again but once it unbinded it never allowed me to click the button anymore.

  • 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-19T01:42:11+00:00Added an answer on May 19, 2026 at 1:42 am

    If “#page-refresh” is really a button (a button or input type="button" element), you can use its disabled property and then set a timeout to restore it:

    $('#page-refresh').click( function() {
        var refreshButton = this;
        $.ajax({
            url: "/page1.php",
            cache: false,
            dataType: "html",
            success: function(data) {
                $('#pagelist').html(data);
                refreshButton.disabled = true;
                setTimeout(function() {
                    refreshButton.disabled = false;
                }, 5000);
            }
        });
        return false;
    });
    

    If it’s not really a button, you can simulate the disabled property. I’ll do it with a class here so you can show the disabled state for the user via CSS:

    $('#page-refresh').click( function() {
        var $refreshButton = $(this);
        if (!$refreshButton.hasClass('disabled')) {
            $.ajax({
                url: "/page1.php",
                cache: false,
                dataType: "html",
                success: function(data) {
                    $('#pagelist').html(data);
                    $refreshButton.addClass('disabled');
                    setTimeout(function() {
                        $refreshButton.removeClass('disabled');
                    }, 5000);
                }
            });
            return false;
        });
    

    Note that in the first case, I’m keeping a reference to the DOM element (var refreshButton = this;), but in the second case I’m keeping a reference to a jQuery wrapper around it (var $refreshButton = $(this);). That’s just because jQuery makes it easy to test/add/remove class names. In both cases, that reference is released once the closures in your event handler are released (in the above, that’s five seconds after the ajax call completes).


    You said specifically you wanted to disable it after the ajax call is complete, but as Marcus points out below, you probably want to disable it when starting the ajax call. Just move the disabling bit up a bit, and add an error handler for the case where success doesn’t get called (error handlers are usually a good idea in any case):

    Real button:

    $('#page-refresh').click( function() {
        var refreshButton = this;
        refreshButton.disabled = true;             // <== Moved
        $.ajax({
            url: "/page1.php",
            cache: false,
            dataType: "html",
            success: function(data) {
                $('#pagelist').html(data);
                setTimeout(function() {
                    refreshButton.disabled = false;
                }, 5000);
            },
            error: function() {                    // <== Added
                refreshButton.disabled = false;
            }
        });
        return false;
    });
    

    Simulated via ‘disabled’ class:

    $('#page-refresh').click( function() {
        var $refreshButton = $(this);
        if (!$refreshButton.hasClass('disabled')) {
            $refreshButton.addClass('disabled');   // <== Moved
            $.ajax({
                url: "/page1.php",
                cache: false,
                dataType: "html",
                success: function(data) {
                    $('#pagelist').html(data);
                    setTimeout(function() {
                        $refreshButton.removeClass('disabled');
                    }, 5000);
                },
                error: function() {                // <== Added
                    $refreshButton.removeClass('disabled');
                }
            });
            return false;
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that performs an ajax call and loads the results into
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
I have this code: if (PsionTeklogix.Keyboard.Keyboard.GetModifierKeyState(Key.Orange) == KeyState.Lock) PsionTeklogix.Keyboard.Keyboard.InjectKeyboardCommand(Function.Orange, 0, 0); if (PsionTeklogix.Keyboard.Keyboard.GetModifierKeyState(Key.Blue) ==
I have this code in my HTML: <h3 id=left>Lorem Ipsum </h3> <h3 id=right>[Current URL
I have this code somewhere in my plugin: $('tr', $this).hover(function(){ var cur_color = null;
I have this code & I've tired using JQuery's appendTo() function to get this
I have this code in the page load...For some reason the dropdown binds to
I have this code and I need an explanation on what it does: function
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:

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.