function manageVoting() {
$("div.votemaincontainer").each(function () {
// variable Declaration and intialization.
var myRating = parseInt($(this).find('#[id$=hfMyVote]').val());
var currentVote = parseInt($(this).find('#[id$=hfCurrentVote]').val());
$('.VoteDownImage').live(click, function () {
ajaxcall(0);
});
$('.voteupImage').live(click, function () {
ajaxcall(1);
});
}
function ajaxcall(a){ // here it's giving error.
var questionID = parseInt($(this).find('#[id$=currentquestionId]').val());
var objectType = 100;
var previousvote = 2;
$.ajax({
url: 'UserControls/Vote/VoteAction.aspx/Voting',
cache: false,
type: 'POST',
data: '{ObjectType: "' + objectType + '", guid: "' + currentGuid + '",previousVote: "' + previousvote + '",vote:"' + a + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
var result = eval(data.d);
}
});
}
$(function () {
// manageVoting();
});
function manageVoting() { $(div.votemaincontainer).each(function () { // variable Declaration and intialization. var myRating =
Share
EDIT: After improving the code indentation in your question, it appears as though you forgot to close the
.each()loop with});before the closing bracket for themanageVoting()function.Proper code indentation is extremely helpful.
Also, it doesn’t make too much sense to apply
.live()in a loop. You only need to do that once.Here’s your code with the improvements:
Original answer:
You don’t specify a type for function parameters (or any other variables) in javascript. This is because of loose typing, where any variable can be used to store any type.
This line:
should be: