title: jquery infinite loop in form submit
body: <p>I've created a custom wordpress plugin that should do the following:</p>
  
  <ul>
  <li>on page load, submits a form</li>
  <li>ajax catches it and does some other functions</li>
  <li>results are returned</li>
  </ul>
  
  <p>Only problem is that the plugin started redirecting to another page and looping infinitely. I've isolated it to the jquery submit code but I can't figure out what I'm doing wrong. I was hoping you folks could lend a sleep-deprived programmer a hand.</p>
  
  <pre><code>  $('#searchform').submit(function(e) {
       e.preventDefault();
       $.ajax({
          type: 'POST',
           url: '../wp-content/plugins/otwcsl/getStores.php',
           data: $('#searchform').serialize(),
           success: function(response) {
             searchLocations(response);
             $('#searchform').unbind().submit();
           }
       });
     });
  </code></pre>
  
  <p>It worked fine on my localhost environment but went berserk on the 'live' website. I can't figure out the disconnect but I'm pretty sure the problem lies here. Thanks in advance!</p>
  
  <p><strong>UPDATE</strong>: I've cut everything down until it looks like this:</p>
  
  <pre><code>$('#searchform').submit(function(e) {
      return false;
  }
  </code></pre>
  
  <p>It's stopped looping but it redirects from <a href="http://www.mypage.com/index.php/locations/" rel="nofollow noreferrer">http://www.mypage.com/index.php/locations/</a> to <a href="http://www.mypage.com/index.php/?s=" rel="nofollow noreferrer">http://www.mypage.com/index.php/?s=</a>. I can't figure it out since it's clearly not ajax that's affecting it.</p>
  
  <p><strong>FINAL UPDATE</strong>: I've finally fixed the problem. I removed all 'submit' functions and used a button click instead. I used the answer found <a href="https://stackoverflow.com/a/8716680/2104627">here</a> in option 3. I'm guessing there was some previous script that was severely messing with the form. Unfortunately, it's not an option for me to go disabling the scripts to find the root cause at this point. Thanks everyone for helping me troubleshoot it!</p>