Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make it so ajax does not run when page loads, but only when submit on a form is pushed?
    primarykey
    data
    text
    <p>I have a form that i want an administrator to fill out, then click submit and have the ajax run. At the moment this works, however, it also runs as soon as the page is loaded, something I do not want to happen. The code is as follows:</p> <pre><code>&lt;script src ="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt; &lt;/script&gt; &lt;script src ="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;style type="text/css"&gt; &lt;/style&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("form").submit(function() { $.ajax({ type: "POST", url: "ajaxtest.php", async:false, data: { product_id: "1" } }).done(function( msg ) { alert( "Data Saved: " + msg ); }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="frmAJAX" action="" method="POST" &gt; &lt;input type="hidden" name="product_id" value="&lt;?php echo $product_id; ?&gt;"/&gt; &lt;p&gt;&lt;strong&gt;ID:&lt;/strong&gt; &lt;?php echo $product_id; ?&gt;&lt;/p&gt; &lt;label name="product_sku" type="text"&gt;Item SKU&lt;/label&gt; &lt;input type="text" value="&lt;?=$product_sku?&gt;" name="product_sku"/&gt;&lt;br /&gt; &lt;label name="product_name" type="text"&gt;Item&lt;/label&gt; &lt;input type="text" value="&lt;?=$product_name?&gt;" name="product_name"/&gt;&lt;br /&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/form&gt; &lt;div id="results"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What I would like to do is keep the ajax from running when the page loads, but let it run when the submit button is used. Any suggestions?</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