Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i get my script/jquery-ajax to continue responding to clicks?
    primarykey
    data
    text
    <p>Still a programming and markup newbie...</p> <p>I have several little in/out button that reads and writes back from a mysql table to track whether different users are available or unavailable. But I can only click the button once to change the status. After that, it stops responding. How can I get it to just keep working? Thanks!!!!</p> <p>list.php</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;script&gt; $(function(){ $(".rating").on("click", function(){ var status = $(this).attr("id").substr(0,1); var id = $(this).attr("id").substr(1); var data = "id="+id+"&amp;status="+status; $.ajax({ type: "POST", url: "rate.php", data: data, success: function(e){ $("#r"+id).html(e); } }) }); }); &lt;/script&gt; &lt;style&gt;.rating { cursor: pointer; }&lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;?php include ("headers.php"); $qq = mysql_query("SELECT * FROM $io"); while($rr=mysql_fetch_array($qq)){ $id = $rr["id"]; $content = $rr["status"]; include("buttons.php"); $list .= '&lt;div style="border-bottom: 1px #32baed solid"&gt;'.$q[0].' &lt;div id="r'.$id.'"&gt;&lt;img class="rating" id="'.$q[0].$id.'" src="'.$color.'"&gt; '.$status.'&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;'; } echo $list; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>rate.php</p> <pre><code>&lt;?php include ("headers.php"); $id = $_POST["id"]; $status = $_POST["status"]; if($status == 0){ mysql_query("UPDATE $io SET status = 1 WHERE id='$id'"); } else { mysql_query("UPDATE $io SET status = 0 WHERE id='$id'"); } include("buttons.php"); $list = '&lt;img class="rating" id="'.$q[0].$id.'" src="'.$color.'"&gt; '.$status; echo $list; ?&gt; </code></pre> <p>buttons.php</p> <pre><code>&lt;?php $q = mysql_query("SELECT status FROM $io WHERE id='$id'"); $q = mysql_fetch_array($q); if($q[0]){ $color = "green.png"; } else{ $color = "red.png"; } ?&gt; </code></pre> <p>headers.php</p> <pre><code>&lt;?php $c = mysql_connect("localhost", "username", "password"); $db = mysql_select_db("likes", $c); $io = 'io'; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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