Note that there are some explanatory texts on larger screens.

plurals
  1. POajax update mysql field without refreshing page
    text
    copied!<p>I'm trying to get my announce box that has a X button on the top right, to be clicked and it remove the message, and update a mysql query field without refreshing the page</p> <p>HTML</p> <pre><code>&lt;form id="myForm" action="delanno.php" method="post"&gt; &lt;div class='announce-box'&gt; &lt;div class='announce-message'&gt;$show_message&lt;/div&gt; &lt;div class='announce-delete'&gt; &lt;a class='deleter'&gt; &lt;button type='submit' id='sub' name='$show_id' style='height:35px; width:40px'&gt; &lt;img src='../css/images/delete_25.png' width='25' height='25'&gt; &lt;/button&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>php (delanno.php)</p> <pre><code>&lt;?php include("conn.php"); foreach($_POST as $name =&gt; $content) { // Most people refer to $key =&gt; $value $something = "$name"; //ignore this, i did this for testing purposes $query = mysql_query("UPDATE announce SET active='disabled' WHERE id='$something' ") or die(mysql_error()); } ?&gt; </code></pre> <p>ajax // This is supposed to update the php field without refreshing or sending to another page</p> <pre><code>&lt;script type="text/javascript"&gt; $("#sub").click( function() { $.post( $("#myForm").attr("action"), $("#myForm :input").serializeArray(), function(info){ $("#result").html(info); }); }); $("#myForm").submit( function() { return false; }); &lt;/script&gt; </code></pre> <p>more ajax // this is supposed to remove the announce div when the delete button is clicked.</p> <pre><code>&lt;script&gt; $('.deleter').on('click', function(){ $(this).closest('.announce-box').remove(); }) &lt;/script&gt; </code></pre> <p>if i remove </p> <blockquote> <p>return false</p> </blockquote> <p>it sends it to the php page and it obviously works. i'm not sure what to do from here</p> <p>EDIT: The script doesn't work unless it's being sent to the php page</p>
 

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