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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:19:21+00:00 2026-05-23T08:19:21+00:00

I am using Ruby on Rails 3.0.7 and jQuery 1.6.1 and I am binding

  • 0

I am using Ruby on Rails 3.0.7 and jQuery 1.6.1 and I am binding an AJAX click event to a link_to HTML output as in the following example:

link_to 'Link name', '#', :id => 'link_css_id'

As you can see I set the URL to ‘#’. Doing that when I click on the link the current view will be moved at the top of the page, as well. Since I don’t like this behaviour, I set nothing (that is, nil or '') for the URL parameter, but on clicking on the link I get an alert message “error” that immediately after disappear. Then in the Firebug Console I get:

uncaught exception: [Exception... "prompt aborted by user" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468" data: no]

How can I solve this issue and avoid the behavior of going at the top of the page on clicking the link?


The AJAX request is:

$jQ('#link_css_id').bind('click', function() {
  $jQ.ajax({
    type:    "POST",
    url:     "<%= user_url(@current_user)%>/test_method",
    data:    "test_data=test",

    error:   function(jqXHR, textStatus, errorThrown) {
      alert(textStatus + ' - ' + errorThrown + '\n\n' + jqXHR.responseText);
      $jQ('#css_id').html('error')
    },
    success: function(data, textStatus, jqXHR) {
      $jQ('#css_id').html('success')
    }
  });
});
  • 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-23T08:19:22+00:00Added an answer on May 23, 2026 at 8:19 am

    The url "#" means an internal anchor is being set. With no name attached to it, it simply focuses on the whole page, and scrolls back up to the top.
    As for using the link_to method, the url attribute is required and cannot be omitted.

    With jquery, you can use preventDefault. This will prevent the default action from the event (e.g.., clicking on a link will open the href url). This is quite useful. You might want to link to an existing page for users that do not have javascript enabled (and where the ajax call won’t work), while it is being ignored by those who do have javascript.

    preventDefault documentation by jQuery.

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

Sidebar

Related Questions

I'm using Ruby on Rails with jQuery and trying to do the following: <%=
I am using jQuery and Ruby On Rails. I have an ajax call $.get()
I'm using jquery-mobile with Ruby On Rails. I want to create a button link
I am trying to make a auto complete box using ruby on rails, jquery
I am using Ruby on Rails 3.0.7 and jQuery 1.6.1. I would like to
We did an application using rails(2.3.4), ruby(1.8.2), MySQL, JavaScript, jQuery. This is handling minimum
I am using Ruby on Rails 3 and I would like to use jQuery
I'm using Ruby on Rails 3 with Ruby 1.9.2. I'm following an article on
I am using Ruby on Rails 3.0.9 and jQuery 1.6.2 I am trying to
I am using Ruby on Rails 3.0.9 and jQuery 1.6.2. I would like to

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.