views:

18

answers:

0
function manageVoting() {
    var parameter;
    var myVoting;
    var divVoting;
    var divVotes;
    var value = -1;
    var parameterData;
    $('div.votemaincontainer').each(function() {
        parameter = $(this).find('#[id$=hfUrl]').val();
        myVoting = parseInt($(this).find('#[id$=hfMyVote]').val());
        divVoting = $(this).find('[id$=divVoting]');
        divVotes = $(this).find('[id$=divVotes]');

        function processVote(value) {
            if (value == 0 || value == 1) {
                parameterData = parameter + value + "'}";

                $.ajax({
                    type: 'POST',
                    url: 'UserControls/Vote/VoteAction.aspx/Voting',
                    data: parameterData,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(data) {
                        var result = eval(data.d);
                        if (result) {
                            if (result.length > 1) {
                                if (result[1] == 1 && result[2] == 1) {
                                    $('img.voteupImage').attr('src', 'UserControls/Vote/Images/aftervote.png');
                                    $('img.votedownImage').attr('src', 'UserControls/Vote/Images/votedown.png');
                                    $(divVotes).html(result[0]);
                                    $(myVoting).val(value);
                                }
                                else if (result[1] == 0 && result[2] == 1) {
                                    $('img.voteupImage').attr('src', 'UserControls/Vote/Images/voteUp.png');
                                    $('img.votedownImage').attr('src', 'UserControls/Vote/Images/aftervotedown.png');
                                    $(divVotes).html(result[0]);
                                    $(myVoting).val(value);
                                }
                                else if (result[2] < 0 && value == 0) {
                                    alert('U HAVE ALL READY VOTED DOWN');
                                }
                                else {
                                    alert('U HAVE ALL READY VOTED UP');
                                }
                                $('#[id$=hfMyVote]').html(result[1]);
                            }
                        }
                        else {
                            alertDialog("voting on any item is only available for Registered User.<br>Do you want to <a class='signUpPopUp' href='signup.aspx'> signup</a> Now?");
                        }
                    },
                    error: function() {


                    }
                });
            }
        }


        $('img.voteupImage').live('click', function() {

            value = 1;
            processVote(value);

        });
        $('img.votedownImage').live('click', function() {

            value = 0;
            processVote(value);

        });
    });
}

$(function() {
    manageVoting();
});

This ajax call i am using for vote up or vote down for a particular list item. But when we click on vote up or vote down image then in parameter = last value of list is only present. suppose if a list view have 5 answer then five times ajax is call with last data item value.

answ1 id=223 ans2 id=224 ans3 id=225 ans4 id=226 ans5 id=227

when we click vote up for ans4 then in parameter value pass 227 instead of 226.

but when i check on client side then each row of list view contain different id. (actually i am using hidden field for storing individual id) then why in parameter value only pass last answer id.

how can i get rid of this problem.