Ajax post multiple IDs, javascript - How to save multiple product IDs together when submitting an order with ajax?

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324175632&siteId=291194637