Monthly Archives: March 2014

Executing common Javascript code at the end of every ajax request :)

Have you ever encountered a situation where you had to call some javascript code after a ajax request is complete and some area of page is reRendered. This normally is the case when your events, some extra UI related javascript gets vanished when elements gets reRendered. For that the solution is to have code inside a javascript function and call it on page load and in oncomplete of commandButton, commandLink, actionFunction etc (all these are ajax request). So for this kind of situation there is a better solution which provides you a place where you can write code which will get called when ever a ajax request is made from page. The trick is that when we do ajax request from page (by any means – commandButton, commandLink, actionFunction etc ) a instance of XMLHttpRequst is created and the ajax request is performed with the help of it. So we can override the method which gets called when the request is completed and put our Javascript code there to get executed. So say bye bye to overload of writting common and duplicate code in oncomplete of every ajax calling commandButton, commandLink etc 🙂 Hope this helps someone.