How to call Javscript after AJAX update, Wicket

Problem

According to this this Wicket article. If we want to run a certain piece of Javascript code after every Ajax update, we can uses “wicketGlobalPostCallHandler” like this :


wicketGlobalPostCallHandler = function {
  alert('successful partial update');
}

However, the solution just doesn’t work for me.

Solution

Alternatively, you can uses “ajaxRequestTarget” to append the Javascrip code :


ajaxRequestTarget.appendJavascript("alert('hello');");

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
4 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
Walter_FritzMateusz MorozWillBob Recent comment authors
newest oldest most voted
Walter_Fritz
Guest
Walter_Fritz

Thank you very much. Found the same before i came to this Page. Wicket doku is sometimes wired!

Mateusz Moroz
Guest
Mateusz Moroz

Great, works like a charm :)

Will
Guest
Will

While adding the javascript to the target, I am getting mixed results. For example, if I debug the Javascript called code, it will work, otherwise it looks as if the function call is added but no executed.

Must note that in my case the target is being closed afterwards:

target.appendJavaScript(“saveCamerasDownload();”);
container.close(target);

Any ideas? :)

Bob
Guest
Bob

Perhaps it doesn’t work because the function declaration is missing the required parentheses after the function keyword.

Using the following declaration does work for me.

wicketGlobalPostCallHandler = function() {
  alert('successful partial update');
}