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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:11:28+00:00 2026-06-05T22:11:28+00:00

I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:

  • 0

I have this very simple jQuery function:

$(".milestone-in-tree").live({
    mouseenter: function() {
        setTimeout(
        $.ajax({
            type: "GET",
            url:"/projects/pmnodes/" + $(this).data("pmnode") + "/addbuttons.js"
        }),5000)
    },
    mouseleave: function() {
        $(".grid-btn").delay(800).remove();
    }
});

I want to make it wait 5 secs before sending the AJAX request to the server but it doesn’t wait, it just sends it right away. Why?

UPDATE:

Thank you for all the feedbacks. I changed the function as it is suggested in all the answers:

$(".milestone-in-tree").live({
    mouseenter: function() {
        var node = $(this).data("pmnode")
        setTimeout(function() {
        $.ajax({
            type: "GET",
            url:"/projects/pmnodes/" + node + "/addbuttons.js"
        }),5000});
    },
    mouseleave: function() {
        $(".grid-btn").delay(800).remove();
    }
});

But I still get no delay. Is there something I misunderstood?
PS: I created the node variable because, for a reason I ignore, $(this) is not accessible anymore inside the SetTimeout anonymous function.

UPDATE 2

Finally, I could manage to get the delay but I realized that the request was still sent to the server after the delay, even if the mouseleave event had been triggered in between…

I could find a workaround. It is totally different. The delay doesn’t work anymore but the ajax requests are aborted on mouseleave events, which is what I really needed. For the ones who might be interested, this is the code:

var button_request;
$(".milestone-in-tree").live({
    mouseover: function() {
        var node = $(this).data("pmnode");
        button_request = $.ajax({
                        type: "GET",
                        url:"/projects/pmnodes/" + node + "/addbuttons.js"
                    });
        setTimeout(function() {button_request;},5000)
    },
    mouseleave: function() {
        if (button_request) {
            button_request.abort();
            button_request = null;
                }
        $(".grid-btn").remove();
    }
});

Of course the setTimeout could be removed (as it doesn’t work…) but I leave it for clarity.

Thanks everyone.

  • 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-05T22:11:29+00:00Added an answer on June 5, 2026 at 10:11 pm

    Try this:

    $(".milestone-in-tree").live({
        mouseenter: function() {
            var pmnode = $(this).data("pmnode"); // cache the data in a variable
            setTimeout( function() { // this function(){...} wrapper is necessary
                $.ajax({
                    type: "GET",
                    url:"/projects/pmnodes/" + pmnode + "/addbuttons.js"
                })
            },5000)
        },
    ...
    

    The first argument of a setTimeout() call needs to be either a string (which you really, really shouldn’t do) or a self-contained function object.

    By putting $.ajax(...) there instead, you’re telling JavaScript to (1) run it immediately and (2) set the first argument as whatever the ajax function returns — which, according to the docs, is a jqXHR object which setTimeout can’t do anything with.

    Just get in the habit of putting an anonymous function(){...} as the first argument of setTimeout() or setInterval() every time you use it, and you’ll be fine.

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

Sidebar

Related Questions

I have this jQuery simple code: <script type=text/javascript> <!-- jQuery(function(){ jQuery('#old_thumb').click(function(){ $(this).val($(this).attr('title')); $('#sf').val('2'); $('#add_new_event').submit();
I have this very simple C++ class: class Tree { public: Node *head; };
I have this very simple jQuery script, which gives me error that delay is
I have a very simple jQuery function that hides most elements until the page
I have this simple piece of code in jQuery $(document).ready(function() { $('#switcher').click(function(event) { if
This looks very simple but I have little experience with jQuery and I can't
I have this code & I've tired using JQuery's appendTo() function to get this
I have a very simple jQuery/ajax script for a membership driven website. The script
I have this very simple form: <form id=header_search><input type=text value=search></form> and this is my
I have a very simple jquery test page and I can't seem to get

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.