jQuery ajax()使用serialize()提交form数据
2021-07-04 06:06
                         标签:ati   序列化   使用   ready   check   .com   ast   tar   action    本文转载自:http://www.cnblogs.com/leejersey/p/3750259.html jQuery的serialize()方法通过序列化表单值,创建URL编码文本字符串,我们就可以选择一个或多个表单元素,也可以直接选择form将其序列化,如: 这样,我们就可以把序列化的值传给ajax()作为url的参数,轻松使用ajax()提交form表单了,而不需要一个一个获取表单中的值然后传给ajax(),举例如下: 使用$.post()、$.get()和$.getJSON()也是一样的: 例2:   jQuery ajax()使用serialize()提交form数据 标签:ati   序列化   使用   ready   check   .com   ast   tar   action    原文地址:http://www.cnblogs.com/mmzuo-798/p/7121211.htmlform action="">
First name: input type="text" name="FirstName" value="Bill" />br />
Last name: input type="text" name="LastName" value="Gates" />br />
form>
$(document).ready(function(){
    console.log($("form").serialize()); // FirstName=Bill&LastName=Gates
});
$.ajax({
    type: ‘post‘,
    url: ‘your url‘,
    data: $("form").serialize(),
    success: function(data) {
        // your code
    }
});
$.post(‘your url‘, $("form").serialize(), function(data) {
        // your code
    }
});
$.get(‘your url‘, $("form").serialize(), function(data) {
        // your code
    }
});
$.getJSON(‘your url‘, $("form").serialize(), function(data) {
        // your code
    }
});
var check = 1;
        $("input[type=‘radio‘]").click(function(){ 
            if(check != 1) { 
                return false;
            }
            var checked_len = $("input[type=‘radio‘]:checked").length;
            var len = Number("{{$queslist|count}}");
            var ques_data = $("#quesform").serialize();
            console.log(ques_data);
            if(checked_len >= len) { 
                $.ajax({
                    type: "POST",
                    url: "__SELF__",
                    data:ques_data,
                    beforSend:function() { 
                        check = 2;
                    },
                    success: function(res) {
                        if(res.status==2000){
                            window.location.href = ‘/Evaluation/index.html‘;
                        } else if (res.state == 101) { 
                            window.location.href = res.url;
                        }else{
                            TipsShow.showtips({info: res.msg});
                        }
                        check=1;
                    }
                });
            }
        });
上一篇:jQuery的val( )方法
下一篇:js对象所有属性转Map
文章标题:jQuery ajax()使用serialize()提交form数据
文章链接:http://soscw.com/index.php/essay/101612.html