0

I have ajaxified links in my rails project:

<%= link_to 'Click me!', some_url, remote: true %>

I added hooks to listen for ajax events:

$(function(){
  $(document).ajaxSend( function(){$('#busy').show()} )
  $(document).ajaxComplete( function(){$('#busy').hide()} )
})

This works as expected in FF.

In Chrome, the #busy div appears as expected when an ajax request is sent, but when the request arrives Chrome goes blank and the console shows a long javascript error message:

jQuery.event.dispatch
elemData.handle.eventHandle
jQuery.event.trigger
(anonymous function)
jQuery.extend.each
jQuery.fn.jQuery.each
jQuery.fn.extend.trigger
... (several hundred lines of pretty much the same stuff)

Why is Chrome barfing on what appears to be a simple addition of an event handler?

4

1 に答える 1

0

これがあなたの質問に直接答えないことはわかっていますが、ajax イベントを処理する Rails の方法は、このページでうまくキャプチャされています: https://github.com/rails/jquery-ujs/wiki/ajax

イベントが上に渡される方法に関係している可能性があります。

<%= link_to 'Click me!', some_url, remote: true, id: 'clickable' %>

$('#clickable').on('ajax:beforeSend', function(event, xhr, settings) {
  $('#busy').show()
});

$('#clickable').on('ajax:complete', function(event, xhr, settings) {
  $('#busy').hide()
});
于 2013-11-21T16:32:16.140 に答える