Jquery serialize()使用

Jquery serialize()可以将form中参数格式化,用于ajax传参。

jQuery.ajax({
        url: url,   // 提交的页面
        data: $("#" + formId).serialize(), // 从表单中获取数据
        type: "POST", // 设置请求类型为"POST",默认为"GET"
        dataType: "json",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8", // 必须要设置为UTF-8,否则提交数据乱码
        beforeSend: function(){
         if(!isunlock){
          new screenClass().lock();
         }
        },
        error: function(msg) {      // 设置表单提交出错
            new screenClass().unlock();
   alert("执行出错:" + msg.responseText);
        },
        success: function(resp) {
          if(!isunlock){
           new screenClass().unlock(); // 设置表单提交完成使用方法
          }
          if(resp.success == false){
          alert("执行失败:" + resp.resultMsg);
          }else if(resp.success == true){
           if(succback == '' || typeof(succback) == "undefined"){
           window.location.href="success.jsp";
           }else{
            succback(resp.attributes);
           }
          }else{
           alert("未知结果:" + resp);
          }
        },
        cache: false
    });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值