如何使用ajax通过html表单传递php切换案例数据?
问题描述:
action="cart.php?action=add&code=<?php echo $product_array[$key]["code"]; ?>"
这是一个表单操作,我试图将数据发送到php代码,其中基于动作切换的情况下,这里的“代码”就是其中之一。如何使用ajax通过html表单传递php切换案例数据?
我无法弄清楚如何发送切换案例数据。
答
你可以这样做,如果你想在提交时做到这一点。
$("#form").submit(function(event) {
$.ajax({
method: "GET",
url: "cart.php",
data: { action: "add", code: "<?php echo $product_array[$key]['code']; ?>" }
})
.done(function(msg) {
alert("Product Added: " + msg);
});
event.preventDefault();
});
+0
我试过了...检查我把警报放在开关盒“添加”它没有执行。 –
我无法弄清楚你的意思。请提供更多信息。 –
在ajax如何发送这样的数据,如$ .ajax({url:'cart.php', 方法:'POST',... \ –