Note that there are some explanatory texts on larger screens.

plurals
  1. POForm not submitting inside $.ajax success function
    primarykey
    data
    text
    <p>I'm validating for duplicate names by using jquery+Ajax. Everything is working fine except that the form is not submitting once everything returns true</p> <p><strong>What's Happening</strong></p> <ul> <li>If no name is entered, alert box is showing up stating name is required --> No problem here</li> <li>If duplicate name is found, alert box is showing up stating name already exists and form does not submit --> No problem here</li> <li>If duplicate name is not found, alert box is showing up (to prove the <strong><code>else</code></strong> part of the condition is working), but the <strong>form does not submit</strong>. I want the form to go ahead and submit itself in this <strong><code>else</code></strong> part</li> </ul> <p><strong>jQuery Code</strong></p> <pre><code>$('#form1').submit(function(){ var name = $('#shelf_name').val(); if(name == '') { alert('Shelf name is required'); $('#shelf_name').focus(); } else { $.ajax({ type:'post', url:'check-duplicate-shelf-name.php', data:{'name':name}, context:this, success:function(data) { if(data == 'stop') { alert('Shelf name already exists'); // working if duplicate name is found } else { alert('else working?'); // alert box is showing up if name is not duplicate this.submit(); // but after alert, this line not executing } } }); } return false; }); </code></pre> <p><strong>HTML Form Tag</strong></p> <pre><code>&lt;form action="add-shelf-post.php" method="post" id="form1"&gt; </code></pre> <p><strong>check-duplicate-shelf-name.php</strong> Page</p> <pre><code>&lt;?php include 'confignew.php'; $name = $_POST['name']; // peforming database operations . . . // and then if($db-&gt;num_rows($q) == 0) { echo 'go'; } else { echo 'stop'; } </code></pre> <p>I'm missing something very obvious. Hopefully someone here can point that out.</p> <p>After checking with Firebug in Firefox, I indeed got an error. It didn't show up when I was testing with Chrome. Here is the screenshot.</p> <p><img src="https://i.stack.imgur.com/rQ75s.png" alt="Firebug Error"></p>
    singulars
    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.
 

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