利用 ajax 像后台传递数组

只需要添加一句话,轻松搞定:

traditional :true    //序列化数据

	 function batchRemove(){
		var ids = new Array();
		$(".collect-goods-box").each(function(){
			var a = ($(this).find(".fl"));
			ids.push(a.attr("goodId"));
		});
		remove(ids);
	}

//移除收藏
	function remove(id) {
		$.ajax({
			url : 'delete.do',
			traditional :true, //默认为false,官方解释:如果你想要用传统的方式来序列化数据,那么就设置为 true。详见 $.param()
			data : {
				'ids' : id
			},
			type : 'post',
			success : function(data) {
				console.log(data);
				if (data.code == 0) {
					window.location.href="list.do"
				} else {
					alert(data.msg);
				}
			}
		});
	}


你可能感兴趣的:(JS,js,ajax,数组,前端序列化)