0
我嘗試在投票後得到json輸出,但投票後我無法獲得成功消息。什麼樣的json輸出我需要寫在投票頁面。請幫助我。我不知道jQuery甚至json,但我適應了這個我的網站一切都很好。投票記錄數據庫成功,但最後一步,我必須寫更新的新投票值,但我coludn't。當我使用錯誤消息時,它會提醒它,但成功時它不起作用。我的頁面是用asp語言編寫的。幫助請。jquery和json響應數據
(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);