The $('.my-button').click(function(e)
function is supposed to show the output of the display.php, which just contains some mysql query and the output in html.
It works so far, but as I am looping the button itself for each post, the function only works for the first button. I need to make the script understand, that for each button it should only show the results for that button. But how to insert some individual ID to the $(".responsecontainer").html(response);
? I tried with $(".responsecontainer" + id).html(response);
getting "id" before via parameters, but it seems that this id must be hardcoded.
Here is the full code:
$(document).ready(function() {
$('.my-button').click(function(e) {
$.ajax({ //create an ajax request to display.php
type: "GET",
url: "display.php",
dataType: "html", //expect html to be returned
success: function(response){
$(".responsecontainer").html(response);
//alert(response);
}
And this is the button and DIV to show results:
<input type="button" class="my-button" value="'.$plus.'" />
<div class="responsecontainer" id="'.$plus.'" align="center">
</div>
Noting that $plus
is always unique.