jquery.ajax和jquery.ajaxSubmit

ajax请求和ajax提交表单

 创建时间: 2014-12-9 17:40   修改时间: 2014-12-30 22:34   
1、ajax
 
    1、引入js(略)
    2、调用$.ajax()方法取得数据
        
        data可以使用 $("#myForm").serialize();
         注意:当使用表格布局时,如果使用ajax刷新出现无来由的多出一列的时候,可以尝试去除结束标记和开始标记之前的空格,参考链接: http://stackoverflow.com/questions/7267014/ie9-table-has-random-rows-which-are-offset-at-random-columns 
示例:
               
1
2
3
4
5
success:function(result){
   result = result.replace(/>\s+(?=<\/?(t|c)[hardfob])/gm, '>' );
   $( "#main" ).empty();
   $( "#main" ).html(result);
}
 
    调用ajax方法代码示例:     
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$.ajax({
        type:  "POST" ,
        url:  "" ,
        dataType: "json" ,
        data:{ "test1" :test1,
              "test2" :test2
        },
         beforeSend:function(){ //在执行action之前调用
            
         },
         async: true , //true为同步,false为异步
        success: function(result, textStatus){
            if (result.code== "00" ){
                alert(" 成功 " );
            } else {
                alert( " 失败 " );
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            alert( " 失败 " );
        }
});
   
    
 
2、ajaxSubmit
 
    1、引入js
 
1
2
<script type= "text/javascript"  src= "${ctx}/js/jquery.form.js" ></script>
<script src= "${ctx}/js/jquery/jquery-1.8.3.min.js"  type= "text/javascript"  ></script>
 
    2、调用ajaxSubmit
 
1
2
3
4
5
6
7
8
9
10
11
12
$( "#myForm" ).ajaxSubmit({
     success:function(data){
         if (data.code ==  '00' ){
               window.location.href=window.location.href;
         } else  if (data.code ==  '01' ){
             $( "#btn" ).alert( "提交失败,请稍候再试" );
         }
     },
     error : function(){
         $( "#btn" ).alert( "提交失败,请稍候再试" );
     }
});
 
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值