$ (". Del_goods"). Click (function () { //delete the selected commodity var clear_data = [];//array $ ("Input[name= ' checkshop[] ']: Checked "). each (function (i) { clear_data[i] = $ (this). Val (); }); $.ajax ({ type: ' Post ', URL: '/wechat.php/cart/delcart/t/', data: {ids:clear_data},// Because Ajax is the JSON format to pass, but we need to pass in the past is an array, so the whole array as a key value of JSON passed through, IDS is a key. If only {Clear_data} is passed, then the key passing past is clear_data. //datatype: ' json ', success:function (jsondata) { alert (jsondata); /*if (jsondata.errmsg = = = ' OK ') { $ ("Input[name= ' checkshop[]:checked ')"). each (function () { $ (this). Parent (). Parent ("Li"). Remove (); }) } */ } }) })
The top pass Array
JSON in the bottom pass
$ (". Del_goods"). Click (function () { ///delete the selected item var clear_data = {};//object $ ("Input[name= ' checkshop[] '): Checked "). each (function (i) { clear_data[i] = $ (this). Val (); });
Clear_data = Json.stringify (clear_data);//Convert object to JSON
Console.log ({clear_data}
$.ajax ({ type: ' Post ', URL: '/wechat.php/cart/delcart/t/', data:clear_data,//pass JSON directly. //datatype: ' json ', success:function (jsondata) { alert (jsondata); /*if (jsondata.errmsg = = = ' OK ') { $ ("Input[name= ' checkshop[]:checked ')"). each (function () { $ (this). Parent (). Parent ("Li"). Remove (); }) } */ } }) })
The data type JSON passed by Ajax