A voting system with jQuery, PHP and Smarty -


i have made voting feature website using php , smarty. this's html part of it:

<p>{$vote} <a href="vote.php?q_vote=vote_up&question_id={$qid}"><i class="icon-thumbs-up"></i></a> <a href="vote.php?q_vote=vote_down&question_id={$qid}"><i class="icon-thumbs-down"></i></a></p> 

the php part of code takes vote , refreshes same page.

i want same thing using jquery won't need refresh page. here wrote in html :

$("#q_upvote").click(function()     {         var vote = "vote_up";         var votedata = "";         votedata = "vote= " + vote;         $.ajax({                                  type: 'post',                 url: 'vote.php',                 data: votedata,                 success: function(vote_msg){                 if(msg == 'ok')                     {                     //show new vote                      }                                         else                                         //show notification                 }     } ) </script> 

i couldn't figure how show new vote there. can me that? appreciate if i'm told if i'm going on right way.

  • corrected html code have placeholder number of votes.

  • corrected ajax call passes same parameters per hrefs in initial upvote anchor.

  • fixed various syntax errors in ajax call

html code

    <p>        <span class="votenumbers">{$vote}</span>         <a id="upvote_{$qid}" class="q_upvote" href="#"><i class="icon-thumbs-up"></i></a>         <a href="vote.php?q_vote=vote_down&question_id={$qid}"><i class="icon-thumbs-down</i</a>    </p> 

jquery code

$(".q_upvote").click(function()     {         var vote = "vote_up",             question_id = this.id.split('_')[1],              votedata = "q_vote="+vote+"&question_id="+question_id;         $.ajax({                                  type: 'post',                 url: 'vote.php',                 data: votedata,                 success: function(vote_msg){                    if(vote_msg== 'ok')                        {                        //show new vote                        $(this).find('.votenumbers').closest().html(parseint($(this).find('.votenumbers').closest().html())+1)                         }                    else{                         //show notification                    }                 }            });     } ) 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -