tags:

views:

143

answers:

2

hey guys, here's my function :

$(".home .up_0").click(function() {
    $.post("includes/vote.php",   
        {truc : $(this).attr("id")},
        function(data) {
            if(data==1) {
                $(this).parents('.home').find('.score_neutre').append(
                    $(this).parents('.home').find('.score_neutre').val()+1
                );
            } else  {
                alert("Error !");
            }
        },
        "json"
    );
});

When I click everything works but it doesn't change the .score_neutre value (which is 1 and I want it to change to 2)

+3  A: 

You need to test (data.score==1) not data

"score" being the associated array name for the json data you sent in.

MindStalker
I don't really get it, in my php file i just send back 1 if it works, and 0 if it doesnt. And it works :|
David 天宇 Wong
+2  A: 

What does your json response look like? You can't compare it like this with a number.

Additionally you are using append which most likely is wrong. I guess want you really wanted to do is

var ele = $(this).parents('.home').find('.score_neutre');
ele.val(ele.val()+1);
jitter
well, append or this doesnt work. I think that it's because it's inside the function(data) that it doesnt work
David 天宇 Wong