Spring和Spring MVC 3.0 AJAX集成

Leo*_*NYC 2 ajax spring spring-mvc

除了这篇文章http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/

我在Spring 3.0中找不到任何关于新AJAX相关功能的好例子.我感兴趣的是如何利用带有Annotations的Spring MVC构建的Web应用程序可以与各种AJAX框架集成,例如Dojo,以在前端提供丰富的用户体验.

Boz*_*zho 6

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);
}
Run Code Online (Sandbox Code Playgroud)

And on the client side, using jQuery:

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