PHPzhong2017-04-11 11:10:131 Floor
The submitted product id can be submitted as a string separated by "," or converted into json format.
For example, separated by ",":
$(".ordersubmit").click(function () {
var goods_str = "";
$('.shopcar').each(function(){
var id = $(this).children().find('dt').attr('value');//订单id
if(goods_str == ""){
goods_str = id+'';
}else{
goods_str = ','+id;
});
orderSubmit(goods_str);
});
//interface
function orderSubmit(goods_str) {
$.ajax({
url: urlApi,
type: 'post',
data: {
goods_id: goods_str,
},
success: function (data) {//},
error: function () {//}
})
}
Logically, the number of goods is not required, because the backend can use functions such as cout to obtain the quantity after the goods_id is parsed.