jQuery: AJAX call isn't updating page
- by Cortopasta
Thought I had a simple AJAX call using $.POST(), but apparently my function isn't firing, and nothing is updating :-/
Here is the call:
$(".answerVerse ul li").click(function(){
var rank = $(this).removeClass("star_empty star_full star_highlight").attr("class");
var verse_id = $(this).parent().parent().find(".verseId").html();
var answer_id = $(this).parent().parent().find(".answerId").html();
var place = this;
$.post("rank.php", { rank: rank, verse_id: verse_id, answer_id: answer_id },function(data){
$(place).parent().removeClass().addClass(data.newVerseRank);
for (i=0;i<=5;i++)
{
$(".answerVerse ul."+i).each(function(){
$(".answerVerse ul."+i+" li."+i).prevAll().andSelf().removeClass("star_empty").addClass("star_full");
});
}
}, "json");
});
And here is the PHP (rank.php) that it calls:
require_once("dbcon.php");
$user = new user();
$user->updateVerseRank($_POST['verse_id'], $_POST['rank']);
$user->getVerse($_POST['verse_id']);
$user->getAnswer($_POST['answer_id'];
$arr = array ('newVerseRank'=>htmlspecialchars(round($user->verse[3])),'newVerseVotes'=>htmlspecialchars(round($user->verse[4])),'newAnswerRank'=>htmlspecialchars($user->answer[3]));
echo json_encode($arr);
Why am I not updating the page? I know it's something dumb I'm doing seeing as how this is my first attempt at AJAX and JSON :-/ Just trying to learn