How to get ID value with jquery and send to PHP script?
I am trying to get an id value of a link with jquery then send that id to a php script (in this case sending it to a php sql query).
I have a link like this on the main page:
<a href="#" id="category1">Category One</a>
when this link is clicked, I would like jquery to grab the id value ('category1') and place it in a seperate php file that holds my db queries.
in other words the id value would be inserted into the query below once the link is clicked so I don't have to manually enter in the category part of the query:
SELECT * FROM maindb WHERE category=开发者_开发问答"category1"
Any help on this would be great, thanks.
<a class='foo' id='category1'>Category One</a>
<a class='foo' id='category2'>Category Two</a>
<a class='foo' id='category3'>Category Three</a>
<script>
$(document).ready(function() {
$('.foo').click(function() {
// You might do:
window.location='somefile.php?id=' + this.id;
// or pass it as an argument to
$.getJSON('somefile', {id: this.id}, function(result) { alert('Success') });
});
});
</script>
精彩评论