$(".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...
}
});
});
过程.php
if ($_POST["which"] = "into") {
$_POST["b"] ++;
}
else{
$_POST["b"] --;
}
echo json_encode($_POST["b"]);
我希望如果单击into
,最终结果会增加,如果单击out
,最终结果会减少。但它总是增加,永远不会减少!
您需要检查条件不分配值
if ($_POST["which"] == "into") {