开发者

Spring and Spring MVC 3.0 AJAX Intergration

开发者 https://www.devze.com 2023-01-07 04:47 出处:网络
Except for this article http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ I cannot find any good examples of the new AJAX related features in Spring 3.0. I am interested in

Except for this article http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/

I cannot find any good examples of the new AJAX related features in Spring 3.0. I am interested in how the web application build utilizing Spring MVC with Annotations can be integrated with the various AJAX frameworks, such as Dojo to provide rich user experience on the f开发者_高级运维ront end.


I think the article is pretty clear about the options. For example, based on it, I created the following method for verifying whether a username is in use or not:

/**
 * @param username
 * @return true if the username is free, false otherwise
 */
@RequestMapping("/account/checkUsername/{username}")
@ResponseBody
public boolean checkUsername(@PathVariable("username") String username) {
    return userService.checkUsername(username);
}

And on the client side, using jQuery:

$("#username").live("blur", function() {
    $.getJSON("account/checkUsername/" + $("#username").val(),
        function(response) {
            // do something with JSON response
        }
    );
});


var xhrArgs = {
url: "account/checkUsername/" +dojo.byId('').value,
handleAs: 'json',
load: function(response) {   response(data);}
}; 

dojo.xhrGet(xhrArgs);


function YourJavaScriptFunctionHere(){
    byObj1.loading()
    setGridData(gridNon,[])
    var url='dispatch=getMETHOD&PARAMETER='+Math.random()*9999;
    var ajax=new ajaxObject('YOUR CONTROLLER MAPPING');
        ajax.callback=function(responseText, responseStatus, responseXML) {
            if (responseStatus == 200) {
                var myArray = eval("("+responseText+")");
                if(myArray["error"]){
                    alert(myArray["error"]);
                }else{
                    setGridData(byObj1,myArray)
                }   
                byObj1.loadingCompleted();
            }
        }
    ajax.update(url,'POST');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消