Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery, ajax button not working
    text
    copied!<p>I have a button that submit data via ajax. Then when I have it change to a different button which then creates a cycle between the two buttons.</p> <p>However the second button isn't click-able. Any idea why? Heres my code:</p> <pre><code>&lt;div class="&lt;?PHP echo $value['id'];?&gt;"&gt;&lt;button class="checkin" id="&lt;?PHP echo $value['id'];?&gt;"&gt;Checkin&lt;/button&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $(function() { // wrap inside the jquery ready() function //Attach an onclick handler to each of your buttons that are meant to "approve" $(".checkin").click(function(){ //Get the ID of the button that was clicked on var id_of_item_to_approve = $(this).attr("id"); $.ajax({ url: "checkin_user.php", //This is the page where you will handle your SQL insert type: "POST", data: "eventid=&lt;?PHP echo $eventId;?&gt;" + "&amp;id=" + id_of_item_to_approve, //The data your sending to some-page.php success: function(){ alert("AJAX request was successfull"); $("." + id_of_item_to_approve).html('&lt;button class="checkout" id="' + id_of_item_to_approve + '"&gt;Check Out&lt;/button&gt;'); }, error:function(){ alert("AJAX request was a failure"); } }); }); //Attach an onclick handler to each of your buttons that are meant to "approve" $(".checkout").click(function(){ //Get the ID of the button that was clicked on var id_of_item_to_approve = $(this).attr("id"); $.ajax({ url: "checkin_user.php", //This is the page where you will handle your SQL insert type: "POST", data: "checkout=1&amp;eventid=&lt;?PHP echo $eventId;?&gt;" + "&amp;id=" + id_of_item_to_approve, //The data your sending to some-page.php success: function(){ alert("AJAX request was successfull"); $("." + id_of_item_to_approve).html('&lt;button class="checkin" id="'+ id_of_item_to_approve +'"&gt;Check In&lt;/button&gt;'); }, error:function(){ alert("AJAX request was a failure"); } }); }); }); &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload