0

I'm using Rails 3 with default javascript library (prototype, I believe) and I want to render a link that makes an AJAX call when pressed.

Here's my sample HAML code:

= link_to "test link", {controller: :information, action: :faq}, remote: true, id: "abc"
:javascript
  $("abc").bind('ajax:beforeSend', function(){
  alert('begin!');
  })

Right now, I'm just testing the code by hand. The idea is that I should click on the link and an alert box should pop up that says "begin!" but no alert dialog pops up when I click on the hyperlink.

I've also tried to switch the binding from ajax:beforeSend to ajax:before, but this doesn't work either.

any ideas on what i'm doing wrong?

Thanks!

user141146
  • 3,285
  • 7
  • 38
  • 54
  • have you checked this post? http://stackoverflow.com/questions/2458841/link-to-syntax-with-rails3-link-to-remote-and-basic-javascript-not-working-in-a . It looks like a similar issue. – Augusto Feb 13 '11 at 18:19
  • augusto, no...i don't think it's the same issue. I have the csrf_meta_tag, so that's not the issue. – user141146 Feb 13 '11 at 18:27

2 Answers2

0

$("#abc").bind('ajax:beforeSend', function(){

You are missing the # for the id

chourobin
  • 4,004
  • 4
  • 35
  • 48
  • if you use chrome or firebug w/ firefox you can check out the console and it will debug all your javascript troubles. (right click > inspect element > console) – chourobin Feb 16 '11 at 03:43
0

I had the same problem.. where did you put the callback code? My first try was to put it in the same link page, but nothing happend. So I move the callback to the application.js, and now it's working.

Dario Barrionuevo
  • 3,007
  • 1
  • 18
  • 17