Home > front end >  Wicket ajax call from client causes error
Wicket ajax call from client causes error

Time:03-03

After a time expires, my client wants us to prompt the user for a possible keepalive to the server. I put an AbstractAjaxBehavior in place, passed the URL to the client and issue the ajax request thusly:

Wicket.Ajax.ajax({u: document._sessionKeepAliveUrl});

The URL in the value there is:

./.?3-1.IBehaviorListener.0-

A breakpoint tells me the onrequest of the behavior is invoked. But then I get the following error on the client side:

Wicket.Ajax:  Wicket.Ajax.Call.failure: Error while parsing response: TypeError: Cannot read properties of null (reading 'getElementsByTagName')

So the solution mostly works. The behavior doesn't do anything with the response. What am I doing wrong. Note, this is Wicket 6 (our client doesn't want to pay for the time to upgrade since they haven't decided on our next framework).

CodePudding user response:

You need to add "wr": false to the attributes:

Wicket.Ajax.ajax({u: document._sessionKeepAliveUrl, "wr": false});

wr stands for "is Wicket Response" [1]. It tells Wicket Ajax/JS whether it should try to interpret the Ajax response or not.

By default Wicket.Ajax.get/post() deals with XML response generated by AbstractDefaultAjaxBehavior, but in your case you use its parent - AbstractAjaxBehavior, that may produce any kind of response, or even no response as in your case.

  1. https://github.com/apache/wicket/blob/3a1a614c1bce68f5eb4e62ae064b48c7bca508df/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java#L69
  • Related