Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f:ajax and jquery's `$(document).ajaxStart` dont work together?

I'm trying to get a 'loading' div for my ajaxified website. using JSF 2.0's f:ajax tag for adding ajax to the website and 'trying' to make the loadin div show using jQuery $(document).ajaxStart function.

The jQuery code part looks like this:

$(document).ajaxStart(function(){
    console.log("ajax start");
  $('#ajaxBusy').show(); 
}).ajaxStop(function(){
    console.log("ajax end");
  $('#ajaxBusy').hide();
});

The log functions are never called. Any Idea why? Do JSF ajax and javascript ajax not work together?

Thanks!

like image 350
Ben Avatar asked Oct 30 '25 00:10

Ben


2 Answers

You should use jsf.ajax.addOnEvent(callback) to display a loading div. Maybe addOnError too.

See the documentation

jsf.ajax.addOnEvent(statusUpdate);
...
var statusUpdate = function statusUpdate(data) {
...
}

You will need to work with data.status

  • begin: before the request is sent
  • complete: request recieved
  • success: request succesfully processed (without errors)

Examples using this api:

  • http://weblogs.java.net/blog/driscoll/archive/2009/10/19/request-aggregation-jsf-2-ajax
  • http://weblogs.java.net/blog/driscoll/archive/2009/05/jsf_2_ajax_even.html
like image 151
Adam Avatar answered Oct 31 '25 15:10

Adam


The shorthand $ can be the problem if using jsf, component libraries and jquery.

Try to call jQuery this way:

jQuery(document).ajaxStart(function(){ ... });
like image 22
Matt Handy Avatar answered Oct 31 '25 15:10

Matt Handy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!