Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery: duplicated submit occurrences when the same form is loaded through ajax
    primarykey
    data
    text
    <p>I have a global form which I want to use the same form every time on submit, and this form is auto generated depends on how many threads are produced from the database. so I might a two or four form of the same kind when the page is loaded. Also, this type of form will be loaded onto the page on certain request through ajax. and the most important is - all these form will use the same submit function.</p> <p>for instance,</p> <p>the html </p> <pre><code>&lt;div class="form"&gt;&lt;/div&gt; &lt;a href="form.php" class="load"&gt;load&lt;/a&gt; &lt;div&gt; &lt;form action="#" method="post" enctype="multipart/form-data" class="form-global"&gt; &lt;textarea name="str_content" title="Write a comment..."&gt;&lt;/textarea&gt; &lt;input type="submit" name="submit" value="SUBMIT" class="button-public left"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;div&gt; &lt;form action="#" method="post" enctype="multipart/form-data" class="form-global"&gt; &lt;textarea name="str_content" title="Write a comment..."&gt;&lt;/textarea&gt; &lt;input type="submit" name="submit" value="SUBMIT" class="button-public left"/&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>below is the working code in jquery,</p> <pre><code>$(document).ready(function() { sumbitform(); $(".load").click(function () { var path = $(this).attr('href'); $('.form').load( path, {}, function(){ sumbitform(); //$(this).bind("submit", sumbitform); }); return false; }); }); this.sumbitform = function(){ $("form.form-global").submit(function(){ alert('1'); return false; }); } </code></pre> <p>all the forms work as normal when the page is loaded, the submit only happens once on each form. but the problem occurs whenever a new form of the same kind is loaded through ajax, the other existing forms will trigger twice.</p> <p>you can see problem on this link, <a href="http://nano-visions.net/dump/jquery.ajaxsubmit/" rel="nofollow">http://nano-visions.net/dump/jquery.ajaxsubmit/</a></p> <p>how can I resolve this problem? can I attach the submit function to the ajax loaded form only like this line below?</p> <pre><code>$(this).bind("submit", sumbitform); // doesn't work obviously </code></pre> <p>or any other better ideas?</p> <p>thanks.</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.
    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