Jquery ajax中的函数调用错误 函数manageVoting(){ var参数; var-myVoting; 无风险投票; 投票权; var值=-1; var参数数据; $('div.votemaincontainer')。每个(函数(){ 参数=$(this.find('#[id$=hfUrl]').val(); myVoting=parseInt($(this).find('#[id$=hfMyVote]').val(); divVoting=$(this.find(“[id$=divVoting]”); divvoates=$(this.find(“[id$=divvoates]”); $('img.voteupImage').live('click',function()){ 如果(myVoting==1){ 警惕(“您已经投票”); } 否则{ 数值=1; } }); $('img.votedownImage').live('click',function()){ 如果(myVoting==0){ 警惕(“您已经投票”); } 否则{ 数值=0; } }); 如果(值==0 | |值==1) { parameterData=参数+值+“'}”; $.ajax({ 键入:“POST”, url:'UserControls/Vote/VoteAction.aspx/Voting', 数据:参数数据, contentType:“应用程序/json;字符集=utf-8”, 数据类型:“json”, 成功:功能(数据){ var结果=评估(数据d); 如果(结果){ 如果(result.length>1){ 警报(“我在这里的结果长度>1”); if(结果[1]==1&&result[2]==1) { $('img.voteupImage').attr('src','UserControls/Vote/Images/aftervote_arrow_up.png'); $('img.votedownImage').attr('src','UserControls/Vote/Images/arrow_down.png'); $('div.divvoces').html(结果[0]); } 其他的 { 警告(“U不能投票超过1”); } $('#[id$=hfMyVote]').html(结果[1]); if(结果[1]==0&&result[2]==1) { $('img.voteupImage').attr('src','UserControls/Vote/Images/Arrow_Up.png'); $('img.votedownImage').attr('src','UserControls/Vote/Images/aftervote_down.png'); $('div.divvoces').html(结果[0]); } 其他的 { 警报(“U不能投票否决超过1”); } } 否则{ $('div.divvoates').html(结果[0]-1); alertDialog(“对任何知识项进行评级仅对注册用户可用。您现在要吗?”); } } }, 错误:函数(){ 警惕(“我是内部错误”); } }); } }); } $(函数(){ 管理投票(); });
我已经编写了上面的代码,但是当我在图像上点击时,$.ajax不会执行代码中的问题。在Jquery ajax中的函数调用错误 函数manageVoting(){ var参数; var-myVoting; 无风险投票; 投票权; var值=-1; var参数数据; $('div.votemaincontainer')。每个(函数(){ 参数=$(this.find('#[id$=hfUrl]').val(); myVoting=parseInt($(this).find('#[id$=hfMyVote]').val(); divVoting=$(this.find(“[id$=divVoting]”); divvoates=$(this.find(“[id$=divvoates]”); $('img.voteupImage').live('click',function()){ 如果(myVoting==1){ 警惕(“您已经投票”); } 否则{ 数值=1; } }); $('img.votedownImage').live('click',function()){ 如果(myVoting==0){ 警惕(“您已经投票”); } 否则{ 数值=0; } }); 如果(值==0 | |值==1) { parameterData=参数+值+“'}”; $.ajax({ 键入:“POST”, url:'UserControls/Vote/VoteAction.aspx/Voting', 数据:参数数据, contentType:“应用程序/json;字符集=utf-8”, 数据类型:“json”, 成功:功能(数据){ var结果=评估(数据d); 如果(结果){ 如果(result.length>1){ 警报(“我在这里的结果长度>1”); if(结果[1]==1&&result[2]==1) { $('img.voteupImage').attr('src','UserControls/Vote/Images/aftervote_arrow_up.png'); $('img.votedownImage').attr('src','UserControls/Vote/Images/arrow_down.png'); $('div.divvoces').html(结果[0]); } 其他的 { 警告(“U不能投票超过1”); } $('#[id$=hfMyVote]').html(结果[1]); if(结果[1]==0&&result[2]==1) { $('img.voteupImage').attr('src','UserControls/Vote/Images/Arrow_Up.png'); $('img.votedownImage').attr('src','UserControls/Vote/Images/aftervote_down.png'); $('div.divvoces').html(结果[0]); } 其他的 { 警报(“U不能投票否决超过1”); } } 否则{ $('div.divvoates').html(结果[0]-1); alertDialog(“对任何知识项进行评级仅对注册用户可用。您现在要吗?”); } } }, 错误:函数(){ 警惕(“我是内部错误”); } }); } }); } $(函数(){ 管理投票(); });,jquery,Jquery,我已经编写了上面的代码,但是当我在图像上点击时,$.ajax不会执行代码中的问题。在单击实时处理程序中,您只设置值参数的值。在此之后,您不会执行其余的代码。尝试类似的方法(未经测试): 函数manageVoting(){ var参数; var-myVoting; 无风险投票; 投票权; var值=-1; var参数数据; $('div.votemaincontainer')。每个(函数(){ 参数=$(this.find('#[id$=hfUrl]').val(); myVoting=parse
单击
实时处理程序中,您只设置值
参数的值。在此之后,您不会执行其余的代码。尝试类似的方法(未经测试):
函数manageVoting(){
var参数;
var-myVoting;
无风险投票;
投票权;
var值=-1;
var参数数据;
$('div.votemaincontainer')。每个(函数(){
参数=$(this.find('#[id$=hfUrl]').val();
myVoting=parseInt($(this).find('#[id$=hfMyVote]').val();
divVoting=$(this.find(“[id$=divVoting]”);
divvoates=$(this.find(“[id$=divvoates]”);
函数processVote(值){
如果(值==0 | |值==1){
parameterData=参数+值+“'}”;
$.ajax({
键入:“POST”,
url:'UserControls/Vote/VoteAction.aspx/Voting',
数据:参数数据,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
var结果=评估(数据d);
如果(结果){
如果(result.length>1){
警报(“我在这里的结果长度>1”);
if(结果[1]==1&&result[2]==1)
{
$('img.voteupImage').attr('src','UserControls/Vote/Images/aftervote_arrow_up.png');
$('img.votedownImage').attr('src','UserControls/Vote/Images/arrow_down.png');
$('div.divvoces').html(结果[0]);
}
其他的
{
警告(“U不能投票超过1”);
}
$('#[id$=hfMyVote]').html(结果[1]);
if(结果[1]==0&&result[2]==1)
{
$('img.voteupImage').attr('src','UserControls/Vote/Images/Arrow_Up.png');
$('img.votedownImage').attr('src','UserControls/Vote/Images/aftervote_down.png');
$('div.divvoces').html(结果[0]);
}
其他的
{
警报(“U不能投票否决超过1”);
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]');
$('img.voteupImage').live('click', function() {
if (myVoting == 1) {
alert(" you have already voted");
}
else {
value = 1;
}
});
$('img.votedownImage').live('click', function() {
if (myVoting == 0) {
alert(" you have already voted");
}
else {
value = 0;
}
});
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) {
alert("i am inside result here result length >1");
if (result[1] == 1 && result[2] == 1)
{
$('img.voteupImage').attr('src', 'UserControls/Vote/Images/aftervote_arrow_up.png');
$('img.votedownImage').attr('src', 'UserControls/Vote/Images/arrow_down.png');
$('div.divVotes').html(result[0]);
}
else
{
alert('U can not vote more than 1');
}
$('#[id$=hfMyVote]').html(result[1]);
if (result[1] == 0 && result[2] == 1)
{
$('img.voteupImage').attr('src', 'UserControls/Vote/Images/Arrow_Up.png');
$('img.votedownImage').attr('src', 'UserControls/Vote/Images/aftervote_down.png');
$('div.divVotes').html(result[0]);
}
else
{
alert('U can not vote down more than 1');
}
}
else {
$('div.divVotes').html(result[0] - 1);
alertDialog("Rating any knowledge item is only available for Registered User.<br>Do you want to <a class='signUpPopUp' href='signup.aspx'> signup</a> Now?");
}
}
},
error: function() {
alert("i am inside error");
}
});
}
});
}
$(function() {
manageVoting();
});
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) {
alert("i am inside result here result length >1");
if (result[1] == 1 && result[2] == 1)
{
$('img.voteupImage').attr('src', 'UserControls/Vote/Images/aftervote_arrow_up.png');
$('img.votedownImage').attr('src', 'UserControls/Vote/Images/arrow_down.png');
$('div.divVotes').html(result[0]);
}
else
{
alert('U can not vote more than 1');
}
$('#[id$=hfMyVote]').html(result[1]);
if (result[1] == 0 && result[2] == 1)
{
$('img.voteupImage').attr('src', 'UserControls/Vote/Images/Arrow_Up.png');
$('img.votedownImage').attr('src', 'UserControls/Vote/Images/aftervote_down.png');
$('div.divVotes').html(result[0]);
}
else
{
alert('U can not vote down more than 1');
}
}
else {
$('div.divVotes').html(result[0] - 1);
alertDialog("Rating any knowledge item is only available for Registered User.<br>Do you want to <a class='signUpPopUp' href='signup.aspx'> signup</a> Now?");
}
}
},
error: function() {
alert("i am inside error");
}
});
}
}
$('img.voteupImage').live('click', function() {
if (myVoting == 1) {
alert(" you have already voted");
}
else {
value = 1;
processVote(value);
}
});
$('img.votedownImage').live('click', function() {
if (myVoting == 0) {
alert(" you have already voted");
}
else {
value = 0;
processVote(value);
}
});
});
}
$(function() {
manageVoting();
});