Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery ajax fails on form submit with link
    primarykey
    data
    text
    <p>In the sequence of this <a href="https://stackoverflow.com/questions/11121733/ajax-form-not-updating-values/11125356#11125356">question</a>, the content I've got in a form is now updating the DB. However, when I click this link </p> <pre><code>&lt;a onclick="doUpdate()" href="#" id="commit-changes" class="uibutton submit_form"&gt;Gravar&lt;/a&gt; </code></pre> <p>The jQuery .ajax function fires the error callback AND updates the DB with the information as well.</p> <p>Here's the code</p> <pre><code>function doUpdate() { e.preventDefault(); $.ajax({ type: "POST", data: $("#validation").serialize(), cache: false, url:"modules/user/updateuser.php", success : function(data){ $("#response-update").html(data); }, error: function(data){ $("#response-update").html("Erro na submissão"); } }); } </code></pre> <p>I'd like to get the success callback, in order to display a nice message to the user when it saves the data.</p> <p>However if I simply do this</p> <pre><code> &lt;a href="#" id="commit-changes" class="uibutton submit_form"&gt;Gravar&lt;/a&gt; &lt;script&gt; $(function(){ $('#commit-changes').click(function(e){ e.preventDefault(); $.ajax({ type: "POST", data: $("#validation").serialize(), cache: false, url:"modules/user/updateuser.php", success : function(data){ $("#response-update").html(data); }, error: function(data){ $("#response-update").html("Erro na submissão"); } }); }); }); &lt;/script&gt; </code></pre> <p>The "submition" doesn't work at all. </p> <p>How can I solve this problem? Been stuck with this part for days! :(</p> <p>EDIT - HTML for the form (This is also a response loaded in the begging of the page)</p> <pre><code> $response.='&lt;form id="validation" method="post"&gt; &lt;fieldset &gt; &lt;input type="hidden" name="user_id" value="'.$_POST['user_id'].'"/&gt; &lt;legend&gt;Actualizar Dados Utilizador&lt;/legend&gt; &lt;div class="section "&gt; &lt;label&gt;Nome&lt;small&gt;Insira o seu nome&lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;input type="text" class="validate[required,custom[onlyLetterSp]] large" name="nome" id="f_required" value="'.utf8_encode($rcs_user-&gt;nome).'"&gt; &lt;/div&gt; &lt;/div&gt;'; $response.='&lt;div class="section "&gt; &lt;label&gt; Email&lt;small&gt;Insira o seu email&lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;input type="text" class="validate[required,custom[email]] large" name="email" id="e_required" value="'. utf8_encode($rcs_user-&gt;email).'"&gt; &lt;/div&gt; &lt;/div&gt;'; $response.= '&lt;div class="section"&gt; &lt;label&gt;Permissões&lt;small&gt;Seleccione o tipo de utilizador &lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;select class="medium" name="role"&gt; '.$role.' &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="section"&gt; &lt;label&gt;Activo&lt;small&gt;Activar utilizador&lt;/small&gt;&lt;/label&gt; &lt;div&gt; '.$activo.' &lt;span class="f_help"&gt;ON / OFF &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="section last"&gt; &lt;div&gt; &lt;a onclick="return doUpdate()" href="#" id="commit-changes" class="uibutton submit_form"&gt;Gravar&lt;/a&gt;&lt;a class="uibutton special" onClick="ResetForm()" title="Limpar Formulário" &gt;Limpar Formulário&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt;&lt;/form&gt; </code></pre>
    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