views:

89

answers:

1

I'm porting working PHP application to Java/Wicket. I have a lot of complex, well written jQuery/javaScript which I would like to reuse and not change too much. Obviously I have to change urls in ajax calls and rewrite the server side scripts from PHP to Java. I tought this task would be simple but somehow I can't figure out how to write server side that would respond to ajax call. Simple example: javascript:

function f(){
            jQuery.ajax({
                data: 'object_type=1&object_id=2',
                url: 'ajax/get_object.php',
                timeout: 2000,
                type: 'POST',
                dataType: 'json',
                success: function(r) {
                    alert(r);
                }
            });
}

Php file ajax/get_object.php:

// ... create $json_string here
echo $json_string;

I have found AbstractDefaultAjaxBehavior which I probably should use to implement server side of such ajax call, but I'm not really sure how to use it. I'm not really Java kind of guy so try to explain step by step what sould I do :-)

+2  A: 

Have a look at This Ajax Wicket tutorial and search for AjaxEventBehavior.

Do note that Wicket assumes that browsers lacking javascript (Braille readers for the disabled for instance) can return full pages (full page reload in stead of AJAX). If you're doing a job for the government that's usually also a requirement.

extraneon