Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with ajax request in page with form. jquery
    primarykey
    data
    text
    <p>I'm making some things with jQuery ajax function, and I have a problem when I put a form in the middle of the html.<br> In a nutshell: I have a dummy form that is controlled by the ajax, when it is submitted the ajax function complets the inputs below. The data submited by the ajax is contained in a form tag that is submitted when a button outside the form is clicked. I made that because I need to send the same data in 2 different ways. <br>The code:<br> HTML</p> <pre><code>&lt;input type="button" value="Exportar a Excel" id="xlsexport"&gt; &lt;form action="#" method="post" name="formxls" id="formxls"&gt; &lt;div class="row"&gt; &lt;input type="hidden" id="xls" name="xls" value=""&gt; &lt;div class="item"&gt;&lt;span class="negro"&gt;Nombre:&lt;/span&gt;&lt;/div&gt; &lt;div class="field"&gt;&lt;input class="input" id="nombreProv" type="text" /&gt;&lt;/div&gt; &lt;div class="item"&gt;&lt;span class="negro"&gt;CUIT:&lt;/span&gt;&lt;/div&gt; &lt;div class="field"&gt;&lt;input class="input" id="cuitProv" type="text" /&gt;&lt;/div&gt; &lt;div class="field"&gt;&lt;input type="image" id="btnEnviar" value="Enviar Prov." src="images/botones/mini_send.png" style="margin-top: -1px; margin-left: 8px;" &gt;&lt;/div&gt; &lt;/div&gt; &lt;/form&gt; ... Some inputs below ... </code></pre> <p><br> jQuery:</p> <pre><code>$('document').ready(function(){ $('#formxls').keypress(function(e){ // it prevents the form will send by pressing enter if(e == 13){ return false; } }); $('#xlsexport').click(function(){ $('#xls').val('true'); $('#formxls').submit(); }); $('input#btnEnviar').click(function(){ if($('#xls').val() == 'true') $('#xls').val(''); $('div#selectData').empty().removeAttr('style'); $.ajax({ // ajax request code }); </code></pre> <p><br></p> <p>The problem is:<br> When I submit the form through the buttom "xlsexport", everything is fine, but then, when I submit the form through the ajax buttom ("btnEnviar"), it does what its supposed to do and then it sends the form, so I lose all the data the ajax loads.<br> How can I solve it? There are other ways to do this? This is a none sense behavior (at least for me), because I dont have other submit than the one in xlsexport click event.</p> <p>I hope I made myself clear and you can help me out with this.</p> <p>Thanks a lot!</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.
 

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