使用ajax增加和减少S_POST变量

时间:2014-10-01 11:29:38

标签: php

$(".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则会减少最终结果。但它总是增加,永不减少!

1 个答案:

答案 0 :(得分:5)

您需要检查条件不分配值

if ($_POST["which"] == "into") {