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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:49:33+00:00 2026-05-29T22:49:33+00:00

I have a link in my rails app setup to make an ajax request

  • 0

I have a link in my rails app setup to make an ajax request

= link_to "link text", some_url, :remote => true

I also have a jquery click handler that will change the url when it is clicked

$('a').click(function() { 
  // change url to "other_url" 
});

The problem is that the link changes BEFORE my ajax request is sent. So the first time it’s clicked, instead of going to “some_url” like it should, it ends up going to “other_url” instead.

Is there a simple/easy way to fix this? Currently I have an ajax:complete bound to the link so once the ajax response returns it will update the link. But this doesn’t work for example if the user clicks on the link quickly a few times since the request isn’t returned yet (thus link isn’t updated yet).

  • 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-29T22:49:36+00:00Added an answer on May 29, 2026 at 10:49 pm

    I would use the ajax:beforeSend callback to disable clicking while the AJAX request is completing. Then, change the URL to the new value in the ajax:complete callback.

    In a click handler

    $('a').click(function(){
      if($(this).attr("disabled") == "disabled"){
        return false;
      }
    });
    

    In the ajax:beforeSend callback something like….

    $('a').removeAttr('data-remote');
    $('a').attr("disabled","disabled");
    

    And then in the ajax:complete callback something like

    // Change the URL...
    $('a').removeAttr('disabled');
    $('a').attr('data-remote','true');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All this weekend I have been trying to setup a Rails 3.0.4 app in
I have some simple jQuery that renders a page in my Rails app. Here's
In my Ruby on Rails 3.1 app I have a link like this: <%=
I have a problem in my rails app that jQuery is included twice. Once
I have a simple jquery auto complete search in my Rails 3 app based
Is there some way to replicate rails' link-to-unless-current? Ie. if i have a list
In my Rails project I have the following code: auto_link( h( wrap_long_string(post.text,50) )).gsub(/\n/,<br />)
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
I have a link that opens a Thickbox... <a href=page.php?tag=lists-element&keepThis=true&TB_iframe=true&height=450&width=500> Everything works with this
How I can setup my rails app to respond to such urls: http://mydomain.com/white-halogene-lamp http://mydomain.com/children-lamps

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.