我尝试在投票后获取 json 输出,但在投票后我无法获得成功消息。我需要在投票页面中写入什么样的 json 输出。请帮助我。我不知道 jquery 甚至 json 但我将它改编为我的网站一切都很好。投票已成功记录数据库,但在最后一步,我必须编写更新后的新投票值,但我没有。当我使用错误消息时,它会提醒它,但成功它不起作用。我的页面是asp语言的。请帮忙。
(function($){
$(function(){
var g='http://my_own_computer.net/';
var h=$('form.thumbsup');
h.submit(function(){return false});
h.find(':input').click(function(){var a=$(this);a.closest('form').trigger('thumsup_vote',[a.val()])});h.bind('thumsup_vote',
function(c,d){
var e=$(this),
template=e.attr('name');
if(e.hasClass('busy')||e.hasClass('disabled'))return;
e.addClass('busy');
var f={small:'<img class="spinner" alt="···" src="'+g+'images/spinner_small.gif" />',large:'<img class="spinner" alt="···" src="'+g+'images/spinner_large.gif" />',large_green:'<img class="spinner" alt="···" src="'+g+'images/spinner_large_green.gif" />',large_red:'<img class="spinner" alt="···" src="'+g+'images/spinner_large_red.gif" />'};
switch(template){
case'buttons':e.find('.question, :button').remove();e.find('.result1').after(' '+f.small);break;
case'mini_poll':e.find('.result1, .result2').html(f.small);break;
case'mini_thumbs':e.find('.result1').html(f.small);break;
case'thumbs_up_down':e.find('.result2').html(f.large_red);
case'thumbs_up':e.find('.result1').html(f.large_green);break;
case'up_down':e.find('.result1').html(f.large);break}
$.ajax({
type:'POST',
url:g+'edit.asp?part=qvote',
cache:false,
dataType:'json',
timeout:15000,
data:{thumbsup_id:e.find('input[name=thumbsup_id]').val(),thumbsup_format:e.find('input[name=thumbsup_format]').val(),thumbsup_vote:d},
error:function(a,b){e.find('.error').text(b)},
success:function(a){if('error'in a){switch(a.error){
case'invalid_id':
e.css('visibility','hidden');
alert('The item you voted on no longer exists.');
break;
case'closed':
e.addClass('closed disabled');
alert('Voting has been closed for this item.');
break;
case'already_voted':
case'ip_blocked':
e.addClass('user_voted disabled');
alert('You have already voted on this item.');
break;
case'login_required':
alert('Oy verebilmek için üyemiz olmalısınız.');
break;
default:alert(a.error)
}
//vote saved but new values coming from the page via json arent being able to print to the page
return}
// The user has voted
e.addClass('user_voted disabled');
for(var i=0;i<a.item.result.length;i++){e.find('.result'+(i+1)).text(a.item.result[i]).fadeTo(0,0.01).fadeTo('slow',1)}
if(template==='mini_poll'){e.find('.graph').css({opacity:0,width:0}).show().filter('.up').animate({opacity:1,width:a.item.votes_pct_up+'%'}).end().filter('.down').animate({opacity:1,width:a.item.votes_pct_down+'%'})}},
complete:function(){e.find('.spinner').remove();e.removeClass('busy')
}})});
$(window).load(function(){if(h.filter('.thumbs_up').length){var a=new Image;a.src=g+'images/spinner_small.gif';var a=new Image;a.src=g+'images/spinner_large.gif';var a=new Image;a.src=g+'images/spinner_large_green.gif';var a=new Image;a.src=g+'images/spinner_large_red.gif'}})})})(jQuery);