Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  130] [ 2]  / answers: 1 / hits: 18022  / 12 Years ago, mon, october 22, 2012, 12:00:00

The following code is what I am currently using to try and give the posts ID to vote.php, however this currently returns [object Object]. How would I be able to pass the correct id when a link is clicked?



<script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script>
<script>
$.ajax({
type: POST,
data: id= + $(this).attr(href, id),
url: vote.php
});
</script>

<a href=javascript:; id=1><div id=button>Like!</div></a>
<a href=javascript:; id=2><div id=button>Like!</div></a>
<a href=javascript:; id=3><div id=button>Like!</div></a>


Thanks!


More From » ajax

 Answers
11

You need to bind the ajax call to a click handler:



$(document).on(click,a,function(e){
$.ajax({
type: POST,
data: id= + $(this).attr(id),
url: vote.php
});
});

[#82429] Saturday, October 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josefinap

Total Points: 548
Total Questions: 125
Total Answers: 106

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;