您可以用于
JSON将表单序列化为
json object,然后用于
AJAX向Web服务发送发布请求:
$(function() { $('#formId').submit(function(event) { event.preventDefault(); // prevent this form from being submited var userJson = JSON.stringify(jQuery('#formId').serializeArray()); $.ajax({ type: "POST", url: "/Path/To/Your/Web/Service", data: userJson, contentType: "application/json; charset=utf-8", dataType: "json", success: function(data){ alert(data);//handle it in a proper way }, failure: function(errMsg) { alert(errMsg);//handle it in a proper way } }); return false; });});然后,在您的WebService上,您应该有一个方法可以处理此发布请求:
@Controller@RequestMapping("/path/to/your/web/service")public class WebServiceController{ @RequestMapping(value = "/login", method = RequestMethod.POST) public ResponseEntity<String> handleLogin(@RequestBody User user){ //user contains data passed from UI form. Check it against your repository(database ? ) }}请注意,该示例仅是一个简单的示例,并且未考虑与安全性相关的任何方面。



