开发者

Rails 3 ajax hyperlink bindings

开发者 https://www.devze.com 2023-02-10 01:20 出处:网络
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.

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 han开发者_JS百科d. 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!


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

You are missing the # for the id


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消