Using Wicket AbstractAjaxBehavior with jQuery.ajax()

前端 未结 2 2048
别那么骄傲
别那么骄傲 2020-12-31 23:03

I have used the jQuery AJax call to send JSON as documented here in StackOverflow

The problem is that I am not receiving any Data on the server . I can see that the

2条回答
  •  抹茶落季
    2020-12-31 23:37

    Another possible solution in wicket 6 and (maybe in wicket 5 if you use wicketAjaxPost instead of Wicket.Ajax.Post), would be to use the Wicket Ajax browser javascript library that way you can use the standard requestCycle.getRequest().getParameterMap() calls in your behavior.

    You can find information about this here:

    https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax

    For example instead of:

    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!")
                    }
    
                });
    

    You could use:

       var success = function() {alert('success!!!')};
       var failure = function() {alert('failure:-(')};
       // ${callbackUrl} is put in through interpolation in the renderHead of the AbstractAjaxBehavior
       //  TextTemplate interpolater = new PackageTextTemplate(ContentTools.class, "PackageInit.js");
    
      // Map variables = new HashMap();
      // variables.put("callbackUrl", getCallbackUrl());
      // interpolater.interpolate(variables);
    
       var callbackUrl =   '${callbackUrl}';
       var dataMap = {'name' : 'Mr Blogs', 'description' : 'a long description'};
       Wicket.Ajax.post({'u': callbackUrl,
          'ep': dataMap, 
          'sh': [success],
          'fh': [failure]
       });
    

提交回复
热议问题