Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit through AJAX from a jQuery generated From
    text
    copied!<p>A page dslogin.php is loaded from a side panel into </p> <pre><code>&lt;div id="workarea"&gt; &lt;/div&gt; </code></pre> <p>The link which loads the page is very simple:</p> <pre><code>&lt;a id=\"ds_action\" href=\"javascript:outputResults('dslogin.php','workarea','db=$k');\"&gt; Connect to $k&lt;/a&gt; </code></pre> <p>but when dslogin get $_GET["db"] it generated a Form which shows up in the workarea div. Now the form is also simple :</p> <pre><code>function getCredentials($db,&amp;$u,&amp;$p) { echo "Connecting to Database $db: &lt;br/&gt;\n"; echo "&lt;form id=\"dblogin\" action=\"dsconnect.php\" method='post'&gt; \n" ; echo" Please enter your username and password if you wish. &lt;br/&gt; \n" ; echo "Username: &lt;input type='text' name='username' &gt; \n " ; echo "Password: &lt;input type='password' name='password' &gt; \n" ; echo "&lt;input type='submit' value='Login' name='Login'&gt; &lt;br/&gt; \n" ; echo "&lt;input type='hidden' value=$db name='database'&gt; &lt;br/&gt; \n" ; echo "&lt;/form&gt;" ; echo "&lt;div id=\"local\"&gt; &lt;/div&gt;"; } </code></pre> <p>Once the users submits the form, an ajax code supposed to intercept it in this following code</p> <pre><code> &lt;script&gt; $(document).ready(function() { $('#dblogin').submit(function() { // catch the form's submit event $.ajax({ // create an AJAX call... data: $(this).serialize(), // get the form data type: $(this).attr('method'), // GET or POST url: $(this).attr('action'), // the file to call success: function(response) { // on success.. $('#local').append(response); // update the DIV } }); return false; // cancel original event to prevent form submitting }); }); &lt;/script&gt; </code></pre> <p>This is NOT working. My thinking is that when the page first loads with the ajax script:</p> <pre><code>$(document).ready(function() { $('#dblogin').submit(function() ... </code></pre> <p>there is no link to the dblogin Form because it was not yet loaded. </p> <p>When you click on submit, you get the action page dsconnect.php instead of getting the output of it appended to the form page as it supposed to do.</p> <p>Is there a way to make this work? </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