我有:
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "
<input type='checkbox' name='additional[{$additional_id}]' value='{$additional_id}'/>{$additional_name} - ${$additional_price} <input type='number' name='quantity_additional[{$additional_id}]' value='1' min='1' max='5'/><br/>
";
}
我需要将此循环中所选复选框的所有值及其数量解析为此查询字符串:
$(document).ready(function()
{
$('.add').on('submit', function()
{
var product_id = $(this).closest('tr').find('.product-id').text();
var product_name = $(this).closest('tr').find('.product-name').text();
var quantity = $(this).closest('tr').find('input').val();
//Here I need to serialize all values and quantities of the selected checkboxes then insert each of them in the Query String below
window.location.href = "add_to_cart.php?product_id=" + product_id + "&product_name=" + product_name + "&quantity=" + quantity;
return false;
});
});
我认为查询字符串需要类似于:
add_to_cart.php?product_id=1&product_name=Pizza&quantity=2&additional_id=1&additional_quantity=2&additional_id=3&additional_quantity=5
输出查询将根据所选附加复选框的数量及其数量。这该怎么做?谢谢!