日期:2014-05-17  浏览次数:20834 次

<Json>提交成功后不跳转

 <div class="container" id="info">

      <form class="form-signin" method="post" id="form" >
        <h2 class="form-signin-heading">添加用户</h2>
        <input type="text" class="input-block-level" placeholder="用户名" name="loginName" id="loginName"/>
        <input type="text" class="input-block-level" placeholder="密码" name="password" id="password"/> 
        <input type="text" class="input-block-level" placeholder="姓名" name="name" id="name"/>
        <input type="text" class="input-block-level" placeholder="email" name="email" id="email"/>
        <input type="text" class="input-block-level" placeholder="电话" name="phone" id="phone"/>
        <button class="btn btn-large btn-primary" type="button" id="submit">添加</button>
      </form>

    </div> 
    

    <script src="${ctx}/static/jquery/1.8.3/jquery.js?v=${version}" type="text/javascript"></script>
    <script src="${ctx}/static/bootstrap/2.3.0/js/bootstrap.min.js?v=${version}" type="text/javascript"></script>
<script src="${ctx}/static/jquery/1.8.3/jquery.json-2.2.min.js?v=${version}" type="text/javascript"></script>
<script type="text/javascript">

$('#submit').click(function(){
var jsonuserinfo = $.toJSON($('#form').serializeObject());
jQuery.ajax({
type:'POST',
contentType:'application/json',
url:'${ctx}/welcome/addUser',
data:jsonuserinfo,
dataType:'json'

});
});
  $.fn.serializeObject = function(){
var o = {};
var a = this.serializeArray();
$.each(a,function(){
if(o[this.name]){
if(!o[this.name].push){
o[this.name]=[o[this.name]];
}
o[this.name].push(this.value||'');
}else{
o[this.name] = this.value ||'';
}
});
return o;
}; 
</script>

我用JSON把值传过去后不跳转. 
下面是我JAVA代码

@RequestMapping(value="/addUser",method = RequestMethod.POST)