开发者

Rails unobtrusive ajax:failure event not firing

开发者 https://www.devze.com 2023-03-11 20:30 出处:网络
I have added success and failure handlers to a :remote => true link generated by rails: HAML: link_to \'Cancel\', cancel_path(block), :method => :delete, :remote => true, :id => \"cancel

I have added success and failure handlers to a :remote => true link generated by rails:

HAML:

link_to 'Cancel', cancel_path(block), :method => :delete, :remote => true, :id => "cancel-button"

JS:

 $('#cancel-button').live('ajax:failure', function(){console.log('failure');});
 $('#cancel-button').live('ajax:success', function(){console.log('success');});

When the response from the server is 200 the console output works - success.

When the response from the server is 404, neither of these handlers fire. No output.

The same is true when the server 开发者_运维知识库returns a 500 status - no output.

Any ideas why rails.js might not be catching this?

Thank you!


Whoops. Contrary to the blog post I was reading the name of the event is actually ajax:error rather than ajax:failure...

0

精彩评论

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