Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Wicket AbstractAjaxBehavior with jQuery.ajax()
    text
    copied!<p>I have used the jQuery AJax call to send JSON as documented here in <a href="https://stackoverflow.com/questions/3168401/json-formatting-sending-json-via-jquery-ajax-post-to-java-wicket-server">StackOverflow</a></p> <p>The problem is that I am not receiving any Data on the server . I can see that the call did reach the target ajax behavior -- but in onRequest() method , the RequestCycle dd not contain any parameters</p> <p>My Wicket Code:</p> <pre><code> AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior(){ private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") public void onRequest() { //get parameters final RequestCycle requestCycle = RequestCycle.get(); final PageParameters pageParameters = new PageParameters(requestCycle.getRequest().getParameterMap()); logger.info(" I have received something 1"); for(String pkey: requestCycle.getRequest().getParameterMap().keySet()){ String[] valArry= requestCycle.getRequest().getParameterMap().get(pkey); StringBuffer sb = new StringBuffer(); for(String s: valArry) sb.append(s).append(" , "); logger.info("pk :"+ pkey + " = "+ sb.toString()); } //do something using nice json library to produce a string of json logger.info(" I have received something 2"); for(String key: pageParameters.keySet()){ Object o= pageParameters.get(key); logger.info("received key : "+ key + " = " +o.toString()); } String data="ok"; requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data)); } }; add(ajaxSaveBehaviour); String callBackURL= ajaxSaveBehaviour.getCallbackUrl().toString(); </code></pre> <p>My Javascript that invokes this method</p> <pre><code>console.log(" call back url :"+ callBackURL); $.ajax({ url: callBackURL, type: 'post', cache: false, data:JSON.stringify(ccbArry[0]), contentType: 'application/json', dataType: 'json', complete: function() { alert(" completed okey dokey!") } }); </code></pre> <p>From my Firebug console, I can see that the JSON POST was made succesfully and the alert(" completed okey dokey!") dos get triggered. </p> <p>The problem is that on the Wicket AbstractAjaxBehavior is unable to find any parameters in the RequestCycle.</p> <p>Is there something I am missing ? The funny thing is that I ran this is debugger asn I could not find any parameter. This looks like an encoding issue.</p> <p>From Firebug, I could see that this was the call that was made </p> <pre><code>http://localhost:8080/mywebapp-web-1.0-SNAPSHOT/?wicket:interface=:0::IActivePageBehaviorListener:0:&amp;wicket:ignoreIfNotActive=true&amp;%7B%22type%22%3A9504%2C%22sourceNewsClipBean%22%3A%7B%22type%22%3A9503%2C%22id%22%3A%224cf05752acc1d6aebface86d%22%2C%22typeString%22%3A%22NEWSCLIP_TYPE%22%7D%2C%22startOffset%22%3A%22195%22%2C%22clipDuration%22%3A%22297%22%7D= </code></pre> <p>Somehow , these parameters do not apperd in the RequestCycle. It looks like an encodong issue . Any ideas ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload