我有以下功能,我想將變量「Quantity」分配給使用Ajax的php變量,但是我對ajax並不瞭解太多,請給我能完成這項工作的代碼。由於如何使用ajax將javascript變量分配給php變量
var Quantity;
$("select").change(function() {
var str = "";
var price = <?php echo $row[price];?>;
$("select option:selected").each(function() {
str += $(this).text() + " ";
});
$(".plan_price").text("price : " + parseInt(str) * price + " baht");
Quantity = parseInt(str);
}).change();
function selectOne() {
var select = document.getElementById('quantity');
for (var i=0; i<<?php echo $row[item_amount]?>; i++) {
select.options[select.options.length] = new Option(i+1, i);
}
}
我想要的數量變量從$行[item_amount]中減去從服務器
if ($row[item_amount] - Quantity == 0) {
$sql = "update item set active='2',item_amount=item_amount-Quantity,buy_time=NOW() where id='$id'";
} else {
$sql = "update item set item_amount=item_amount-Quantity,buy_time=NOW() where id='$id'";
}
$result = mysql_query($sql);
Java **不是** JavaScript。 – 2013-04-29 00:09:54
谷歌關於JavaScript&POST方法 – 2013-04-29 00:11:56
我發現最好的方法是從你的PHP中分離HTML/JS/CSS。我不會從我的PHP生成「代碼」。我使用php作爲ajaxing的「數據源」。代碼應該是靜態的,我還沒有找到一個原因代碼應該是動態的(除了插件),而不是「打動」某人。 – Rahly 2013-04-29 00:55:11