Hi all,
I'm trying to create a Stackoverflow like voting system, and I've run into a slight problem.
I have the following HTML that has jQuery onClick events wired to it:
<div id="c_<%=Html.Encode(Model.C.cID) %>" class="votes">
<img src="../../Content/gfx/Up.png" class="up" alt="" />
<span class="votecount"><%= Html.Encode(Model.C.VoteCount)%></span>
<img src="../../Content/gfx/Down.png" class="down" alt="" />
</div>
The jQuery onClick looks like this:
$(".up").click(function() {
var id = $(this).parent().attr("id").split("_");
if (id[0] == "c") {
//C Vote
//id[1] contains the id number.
$.post("/Vote/CUp", { id: id[1] }, function(data) {
$(this).parent().children(".votecount").html(data.voteCount);
},
"json"
);
} else {
//R Vote
$.post("/Vote/RUp", { id: id[1] }, function(data) {
$(this).parent().children(".votecount").html(data.voteCount);
},
"json"
);
};
});
My problem lies in trying to update the vote count. I just can't work out how to update the votecount span with the values returned in the JSON object.
The JSON object is returning data, I've verified this using alert(data)
Help is much appreciated.