Unable to make JQuery function work
So, I have generated a table with a 'while' loop in php/mysql, and I want the user to be able to click an up arrow button with AJAX / JQuery and have it add +1 to an integer in the database AND display that new value on the page. I had this problem already solved, but by making changes elsewhere in my script somehow it has stopped working. Let me show you what I have.
Here is php script, echoing the table. I create an up arrow, then display the points (that I later want to add +1 to).
<div id="new_UpArrow">
<a href="javascript:void(0)" class = "new_upArrow"
rowid="' . $row['item'] . '"><img src="../Img/new_upArrow.gif"/>
</a> </div>';}
///////////POINTS/////////////
echo ' <div class = "points" id="' . $row['item'] . '">'. $row['points'] . '</div>
Here is the JQuery. I first send a GET statement to add +1 to the database, then I need it to display the new +1 value on the page for the user.
//upArrow
$('.new_upArrow').click(function(){
var row = $(this).attr('rowid');
$.开发者_StackOverflow中文版ajax({
type: "GET",
url: "upVote.php?id="+row,
cache: false,
async: false,
context: $('#'+row),
success: function(result) {
$(this).html(parseInt($(this).html()) + 1);
},
error: function(result){
alert('Voting error, please try again.');
}
});
});
Again, this was working just fine a day ago, and now I can't get it to work again. What is going on??
Thanks guys!!
edit: After some further debugging here is where I am:
jQuery is pulling rowid from my php just fine as I am able to echo that variable. However, even if I MANUALLY enter that ID into the 'context' part, the script fails. I am unable to focus jQuery on my 'points' div.
(edit: OK, my first suggestion was very stupid, I didn't read the question properly, sorry about that)
Have you tried just using the selector inside the success function, instead of $(this)
? The row
variable is in a closure, so you can just reuse that...
精彩评论