I want to post a varible "id" to a page. I'm trying following code, but I cant get the id value, it says "undefined".
function box(){
var id=$(this).attr("id");
$("#votebox").slideDown("slow");
$("#flash").fadeIn("slow");
$.ajax({
type: "POST",
//I want to post the "id" to the rating page.
data: "id="+$(this).attr("id"),
url: "rating.php",
success: function(html){
$("#flash").fadeOut("slow");
$("#content").html(html);
}
});
}
This function is called in following code. In the following code too, the id is posted to the page "votes.php", and it works fine, but in the above code when I'm trying to post the id to the rating.php page, it does not send.
$(function(){
$("a.vote_up").click(function(){
the_id = $(this).attr('id');
$("span#votes_count"+the_id).fadeOut("fast");
$.ajax({
type: "POST",
data: "action=vote_up&id="+$(this).attr("id"),
url: "votes.php",
success: function(msg)
{
$("span#votes_up"+the_id).fadeOut();
$("span#votes_up"+the_id).html(msg);
$("span#votes_up"+the_id).fadeIn();
var that = this;
box.call(that);
}
});
});
});
rating.php
<?
$id = $_POST['id'];
echo $id;
?>
The html part is:
<a href='javascript:;' class='vote_up' id='<?php echo $row['id']; ?>'>Vote Up!</a>
I'll appriciate any help.