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


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

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

使用$.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/

 

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

e.g. 

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

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

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

 

顯然傳統方式會產生值的覆蓋,所以默認是:false,

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM