Update Database With Html Link Click Using Ajax Php Mysql
I've read through a number of similar questions and tried my hand at putting it to work on my website, but it is not working (when you click the link there is no response on the co
Solution 1:
Firstly you should change the way you are detecting the click event. Check out this fiddle. Then secondly you need to pass all the variables through in one JSON string using the data option. Your code should look something like this:
<spanclass="glyphicon glyphicon-chevron-up clickable"data-rating="1"data-id="<?phpecho$thisperspective_row['id']; ?>"></span><scripttype="text/javascript">
$('.clickable').on('click', function() {
var data = {
mode: "vote",
rating: $(this).data('rating'),
id: $(this).data('id')
};
$.ajax({
type: 'GET',
url: 'rating.php',
data: data,
success: function(response) {
console.log(response);
}
});
});
</script>
Solution 2:
First off all, check that you are loading jQuery, then use this code
functionupdateRating(rating, id){
$.ajax({
type: "GET",
url: "rating.php",
mode: "vote",
data: { rating: rating, id: id },
success: function(response) {
console.log(response);
}
});
returnfalse; // Prevent the browser from navigating to the-script.php
};
is working for me. note that I removed ` inside Ajax, since you are already sending the params in the function, also to send params you have to use data:, you can see more examples here Ajax jQuery
Post a Comment for "Update Database With Html Link Click Using Ajax Php Mysql"