Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery/Ajax form not submitting
    primarykey
    data
    text
    <p>I'm pulling my hair out over this one - I have a page that searches a MySQL database and returns the results in a table. I want the user to be able to update the results and hence update the MySQL database. The first part works ok, I have a search box on the page, which uses jQuery/ajax to query the database and display the results, e.g.:</p> <pre><code>&lt;form class="well" id="jquery-submit-ajax" method="post"&gt; &lt;input type="text" name="userSearch" placeholder="Search…"&gt; &lt;label&gt;Name/Email/id&lt;/label&gt; &lt;Br /&gt; &lt;input type="submit" id="searchButton" value="Search"&gt; &lt;/form&gt; &lt;div class="alert alert-success hide"&gt; &lt;div id="success-output" class="prettyprint"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="loading-image" class="alert hide" style="text-align:center"&gt; &lt;img src="../images/ajax-loader.gif" /&gt;&lt;/div&gt; &lt;div class="alert alert-error hide"&gt; &lt;div id="error-output" class="prettyprint"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and the jQuery:</p> <pre><code>$("#jquery-submit-ajax").submit(function(e) { $('#loading-image').fadeIn(); $.ajax({ type: "POST", url: "jquery-ajax-control.php", data: $(e.target).serialize(), dataType: "html", beforeSend:function(){ $('.alert-error,.alert-success').hide(); }, error: function(jqXHR, textStatus, errorThrown){ $('#loading-image').hide(); $('.alert-error').fadeIn(); $('#error-output').html(errorThrown); }, success: function(data){ $('#loading-image').hide(); $('.alert-success').fadeIn(); $('#success-output').html(data); } }); return false; }); </code></pre> <p>So the results are parsed into a table for each result. Within that table is a form with a submit button. e.g.:</p> <pre><code>&lt;form method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" class="editbox" name="subs-expiry" value="&lt;?php echo $expiry_date; ?&gt;"&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" class="updateSubsButtons" value="Update" /&gt; &lt;/form&gt; </code></pre> <p>I'm trying to submit this form via jQuery/Ajax again, but I can't get it to work. Pressing the Update button results in the whole page refreshing. I've stripped the jQuery for this button right back to just display an alert when the button is pressed, but even that doesn't work.</p> <pre><code>$(".updateSubsButtons").on("submit", function(e){ alert("clicked"); e.preventDefault(); }); </code></pre> <p>Using the Chrome debugger a breakpoint in the function never gets hit, so maybe jQuery can't find the button? I've tried .on() and .live() functions, but I get the same result with both. I really can't figure out what's going on here, so any help would be gratefully received!</p>
    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.
    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