Ajax post return value

JamesBZ

New Member
Im using Ajax to send values to a PHP script which writes some value to a database:\[code\]$.ajax({ type: "POST", data: "action=vote_down&id="+$(this).attr("id"), url: "vote.php", success: function(msg) { $("span#votes_count"+the_id).fadeOut(); $("span#votes_count"+the_id).html(msg); $("span#votes_count"+the_id).fadeIn(); }});\[/code\]As you can probably tell from the \[code\]action=vote_down\[/code\] the script is for a voting script. Im already preventing the user from voting more than once by logging there vote against there username and ID in \[code\]vote.php\[/code\] and if there username and ID is already in the DB against the same post then I dont add the vote to the DB.I personally think that querying the database on each page load to check if the user has already voted could be quite intensive, there are many places to vote on a single page.So instead i'll show the user the voting option, but when they vote I want to some how return a value from \[code\]vote.php\[/code\] to say they have already voted.Any ideas for the best approach to this?
 
Back
Top