jquery ajax post 傳遞數組 ,多checkbox 取值

jquery ajax post 傳遞數組 ,多checkbox 取值jquery

http://w8700569.iteye.com/blog/1954396ajax

使用$.each(function(){});能夠獲得checkbox 中對應的值,數組

在ajax上傳的時候須要把 traditional 設置爲 true 框架

 

$('.but_delet_choice').click(function(){  
                var $check_boxes = $('input[type=checkbox][checked=checked][id!=check_all_box]');  
                if($check_boxes.length<=0){ alert('您未勾選,請勾選!');return;   }  
                if(confirm('您肯定要刪除嗎?')){  
                    var dropIds = new Array();  
                    $check_boxes.each(function(){  
                        dropIds.push($(this).val());  
                    });  
                    $.ajax({  
                        type:'post',  
                        traditional :true,  
                        url:'${ctx}/discuss/dropMoreRmb',  
                        data:{'dropIds':dropIds},  
                        success:function(data){  
                            refreshRmb(1);  
                        }  
                    });  
                }  
                return false;  
            });  

 

jQuery ajax traditional參數

http://chaodongyue.blog.163.com/blog/static/100209315201401645813576/post

 

官網註釋:Set this to true if you wish to use the traditional style of param serialization.
意識是,當設置成true的時候就會用傳統方式序列化參數
 

e.g. this

當提交的參數是數組 {name:[value1,value2,value3]} url

若是設置成true,則提交時會是"name=value1&name=value2..."spa

若是是false的話,則提交時會是"name[]=value1&name[]=value2..."code

 

顯然傳統方式會產生值的覆蓋,因此默認是:false,對象

jquery會深度序列化參數對象,以適應如PHP和Ruby on Rails框架.

相關文章
相關標籤/搜索