Reputation: 1549
My request ajax dont call the function to appear the gif of loading, im use a sample ajax requisition, my js is:
$("#carregar").bind("ajax:loading", function(et, e){
$(this).hide();
$("#load_img").show();
});
im using the sample method of controller.js.erb and load the content but the gif dont appear please what is wrong ? thanks
Upvotes: 0
Views: 738
Reputation: 12643
ajax:loading
was an event triggered by the JS driver which shipped with older versions of jquery-rails. It has since been altered. If you are using a more recent version of Rails then you should bind to the ajax:beforeSend
event.
Other things to consider:
1) Handlers for the ajax:beforeSend
event should be bound to the element which triggered the AJAX request, most likely a FORM element.
2) When using jQuery .bind() the target element needs to be present in the DOM. An easy way ensure the DOM is loaded before you bind event handlers is to wrap your script in document ready callback.
$(document).ready(function(){
$("#carregar").bind(...)
})
3) Arun's suggestion about using ajaxStart would be good for showing and hiding the ajax loading indicator.
// Show and hide the indicator for every AJAX request.
$(document).ajaxStart(function(){
$("#load_img").show();
});
$(document).ajaxStop(function(){
$("#load_img").hide();
});
Upvotes: 2
Reputation: 119
Refer to the jQuery documentation for events triggered.
Try binding the ajax:before
event instead of ajax:loading
.
Upvotes: 0