ajax提交整个form

前台页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
<span style="white-space:pre">	</span>pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/WEB-INF/jsp/public/common.jspf"%>
</head>
<body>
<form id="registerForm">
<div style="margin:20px 0;"></div>
<span style="white-space:pre">	</span><div class="easyui-panel" title="用户注册" style="width:400px;padding:10px 60px 20px 60px">
<span style="white-space:pre">		</span><table cellpadding="5">
<span style="white-space:pre">			</span> <tr>
<span style="white-space:pre">				</span><td>用&nbsp;户&nbsp;名:</td>
<span style="white-space:pre">				</span><td><input type="text" name="username" class="easyui-validatebox textbox" data-options="prompt:'输入你的用户名.',required:true,validType:'length[3,10]'"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
<span style="white-space:pre">				</span><td><input type="password" name="password" class="easyui-validatebox textbox" data-options="prompt:'请输入密码.',required:true,validType:'passoword'"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>确认密码:</td>
<span style="white-space:pre">				</span><td><input type="password" name="password2" class="easyui-validatebox textbox" data-options="prompt:'请确认你的密码.',required:true,validType:'passoword2'"></td>
<span style="white-space:pre">				</span>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>昵&nbsp;&nbsp;&nbsp;&nbsp;称:</td>
<span style="white-space:pre">				</span><td><input name="nickname" class="easyui-validatebox textbox" data-options="prompt:'请输入你的昵称.',required:true,validType:'length[3,10]'"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span> <tr>
<span style="white-space:pre">				</span><td>生&nbsp;&nbsp;&nbsp;&nbsp;日:</td>
<span style="white-space:pre">				</span>
<span style="white-space:pre">				</span><!-- <td><input name="birthday" class="easyui-datebox"></td> -->
<span style="white-space:pre">				</span><td><input name="birthday"class="easyui-datebox"></td>
<span style="white-space:pre">			</span></tr> 
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</td>
<span style="white-space:pre">				</span><td><input name="email" class="easyui-validatebox textbox" data-options="prompt:'Enter your phone number.',required:true,validType:'email'"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>手&nbsp;&nbsp;&nbsp;&nbsp;机:</td>
<span style="white-space:pre">				</span><td><input name="phone" class="easyui-validatebox textbox" data-options="prompt:'Enter your phone number.',required:true"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>住&nbsp;&nbsp;&nbsp;&nbsp;址:</td>
<span style="white-space:pre">				</span><td><input name="address" class="easyui-validatebox textbox" data-options="prompt:'Enter your phone number.',required:true"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>性&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
<span style="white-space:pre">				</span>
<span style="white-space:pre">				</span><td><input type="radio" value="0" name="gender"
<span style="white-space:pre">					</span>checked="checked">男 <input type="radio" value="1"
<span style="white-space:pre">					</span>name="gender">女</td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td>备&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
<span style="white-space:pre">				</span><td><textarea rows="5" cols="21" name="description"></textarea></td>
<span style="white-space:pre">			</span></tr> 
<span style="white-space:pre">			</span><tr>
<span style="white-space:pre">				</span><td></td>
<span style="white-space:pre">				</span><td><input type="button" id="regBtn" value="注册"
<span style="white-space:pre">					</span>οnclick="testtt()"><input type="reset" value="重置"></td>
<span style="white-space:pre">			</span></tr>
<span style="white-space:pre">			</span>
<span style="white-space:pre">		</span></table>
<span style="white-space:pre">	</span></div>
<span style="white-space:pre">	</span></form>
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span><style scoped="scoped">
<span style="white-space:pre">		</span>.textbox{
<span style="white-space:pre">			</span>height:20px;
<span style="white-space:pre">			</span>margin:0;
<span style="white-space:pre">			</span>padding:0 2px;
<span style="white-space:pre">			</span>box-sizing:content-box;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span></style>
<span style="white-space:pre">	</span><script>
<span style="white-space:pre">		</span>$(function(){
<span style="white-space:pre">			</span>$('input.easyui-validatebox').validatebox({
<span style="white-space:pre">				</span>tipOptions: {<span style="white-space:pre">	</span>// the options to create tooltip
<span style="white-space:pre">					</span>showEvent: 'mouseenter',
<span style="white-space:pre">					</span>hideEvent: 'mouseleave',
<span style="white-space:pre">					</span>showDelay: 0,
<span style="white-space:pre">					</span>hideDelay: 0,
<span style="white-space:pre">					</span>zIndex: '',
<span style="white-space:pre">					</span>onShow: function(){
<span style="white-space:pre">						</span>if (!$(this).hasClass('validatebox-invalid')){
<span style="white-space:pre">							</span>if ($(this).tooltip('options').prompt){
<span style="white-space:pre">								</span>$(this).tooltip('update', $(this).tooltip('options').prompt);
<span style="white-space:pre">							</span>} else {
<span style="white-space:pre">								</span>$(this).tooltip('tip').hide();
<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>} else {
<span style="white-space:pre">							</span>$(this).tooltip('tip').css({
<span style="white-space:pre">								</span>color: '#000',
<span style="white-space:pre">								</span>borderColor: '#CC9933',
<span style="white-space:pre">								</span>backgroundColor: '#FFFFCC'
<span style="white-space:pre">							</span>});
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>},
<span style="white-space:pre">					</span>onHide: function(){
<span style="white-space:pre">						</span>if (!$(this).tooltip('options').prompt){
<span style="white-space:pre">							</span>$(this).tooltip('destroy');
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}).tooltip({
<span style="white-space:pre">				</span>position: 'right',
<span style="white-space:pre">				</span>content: function(){
<span style="white-space:pre">					</span>var opts = $(this).validatebox('options');
<span style="white-space:pre">					</span>return opts.prompt;
<span style="white-space:pre">				</span>},
<span style="white-space:pre">				</span>onShow: function(){
<span style="white-space:pre">					</span>$(this).tooltip('tip').css({
<span style="white-space:pre">						</span>color: '#000',
<span style="white-space:pre">						</span>borderColor: '#CC9933',
<span style="white-space:pre">						</span>backgroundColor: '#FFFFCC'
<span style="white-space:pre">					</span>});
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>});
<span style="white-space:pre">		</span>});
<span style="white-space:pre">	</span></script>
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span><script type="text/javascript">
<span style="white-space:pre">		</span>function testtt() {
<span style="white-space:pre">			</span>$.ajax({
<span style="white-space:pre">				</span>cache : true,
<span style="white-space:pre">				</span>type : "post",
<span style="white-space:pre">				</span>url : "user/register.do",//提交action的地址
<span style="white-space:pre">				</span>data : $("#registerForm").serialize(),//registerForm 表单ID
<span style="white-space:pre">				</span>dataType : "json",
<span style="white-space:pre">				</span>async:false,
<span style="white-space:pre">				</span>success : function(data) {
<span style="white-space:pre">					</span>alert(data.msg);
<span style="white-space:pre">				</span>},
<span style="white-space:pre">				</span>error : function(request) {
<span style="white-space:pre">					</span>alert("Connection error");
<span style="white-space:pre">				</span>}


<span style="white-space:pre">			</span>});


<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span></script>
</body>


后台接收

package com.poobo.quote.controller;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.poobo.quote.model.User;
import com.poobo.quote.service.UserService;
import com.poobo.quote.util.LogRecord;
import com.poobo.quote.util.PathUtil;

@Controller
@RequestMapping("/user")
public class UserRegister
{

	Logger log = Logger.getLogger(UserRegister.class);
	@Autowired
	private UserService userService;

	/**
	 * 定位到注册页面
	 * 
	 * @return
	 */
	@RequestMapping("/goRegister.do")
	public Object backRegisterPage()
	{
		return new ModelAndView(PathUtil.userPath + "register");
	}

	/**
	 * 用户注册
	 * 
	 * @param request
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/register.do", produces = "text/html; charset=utf-8")
	@ResponseBody
	public String test(HttpServletRequest request, User user)
	{
		String strJson = "{\"msg\":\"注册失败\"}";
		if("".equals(user.getUsername())||null==user.getUsername()){
			return "{\"msg\":\"用户名必填\"}";
		}
		if (!user.getPassword().equals(user.getPassword2()))
		{
			return "{\"msg\":\"两次输入密码不一致\"}";
		}
		if (user.getPassword().length() < 6)
		{
			return "{\"msg\":\"密码长度不能小于6位\"}";
		}
		user.setPk_id(UUID.randomUUID().toString());
		userService.save(user);
		strJson = "{\"msg\":\"注册成功\"}";
		LogRecord.operation("插入成功了!");
		return strJson;
	}
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值