$(".into, .out").click(function(){
var which = $(this).attr("class");
alert (which); // `into` or `out` depending what is clicked
var b = $(this).siblings().children(".count").html(); // starting value is `0`
$.ajax({
type: "POST",
dataType: "json",
url: "process.php",
data: {which:which, b:b},
context: this,
success: function(data) {
alert (data); // 1, 2, 3...
}
});
});
process.php
if ($_POST["which"] = "into") {
$_POST["b"] ++;
}
else{
$_POST["b"] --;
}
echo json_encode($_POST["b"]);
如果点击into
,我希望最终结果会增加,如果点击out
则会减少最终结果。但它总是增加,永不减少!
答案 0 :(得分:5)
您需要检查条件不分配值
if ($_POST["which"] == "into") {