var row1 = {}; row1.name = 'david'; row1.age = '20'; //或者 var row2 = {name: 'peter', age: '23'}; var data = []; data.push(row1); data.push(row2); //此时data的json字符串为 [{name:'david',age:'20'},{name:'peter',age'23'}] //如果后台是PHP,将得到 /* print_r($_GET); Array(0=>array('name' => 'david'.... */ 但是建议采用如下的形式 var data = {records: []}; data.records.push(row1); data.records.push(row2); //此时data的json字符串为 {records:[{name:'david',age:'20'},{name:'peter',age'23'}]} //如果后台是PHP,将得到 /* print_r($_GET); Array( 'records' => array( 0 => array( 'name' => 'david' .... */
$('#setauth').click(function(){ var Ul = $('#autform').find(':text'); var all = []; for(var i=0;i<Ul.length;i++) { all.push({key: UI[i].name, val: Ul[i].value}); } $.post(url,all,function(data){... }); })