Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to handle ajax resonseText with conditions
    primarykey
    data
    text
    <p>I have gotten my form to post with ajax, and all works well. As far as ajax is concerned, it processed its job successfully with a responseText. But that doesn't mean that everything processed correctly in my case. </p> <p>ajax is posting my form which runs a php file to insert data into my database. Success or fail, there will be a responseText that either says: "Thank you" if all data was inserted into db, or "Err:" if it failed. </p> <p>How do I make an if condition from that responseText to handle that kind of custom responseText error? Or can I force it to return an .ajaxError() upon the responseText of "Err:"?</p> <p>HTML form:</p> <pre><code>&lt;form method="post" action="contact.php" id="contact"&gt; &lt;fieldset&gt; &lt;input type="text" id="email" class="required email" name="email" maxlength="30" value="youremail @ example.com" /&gt; &lt;input type="text" id="subject" class="required" name="subject" maxlength="24" value="Enter your subject" /&gt; &lt;textarea id="msg" class="required textarea" name="msg" cols="30" rows="5"&gt;Reason for contact.&lt;/textarea&gt; &lt;input type="submit" class="formBtn" value="Punch me an Email" /&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>JQuery:</p> <pre><code>$(window).load(function(){ $('#contact').ajaxForm({ beforeSubmit:formValidate, success: showResponse, clearForm:true }); }); function formValidate(){ $('#contact').validate({ rules:{ email:{required: true, email:true}, subject:{required: true, minlength: 5}, msg:{required: true, minlength: 50} }, messages:{ email:'', subject: '', msg: '' }, invalidHandler:function(){ $('div.error').hide(); }, focusInvalid:true, onfocusout:false, submitHandler: function() { $('#contact').ajaxSubmit(); } }); } function showResponse(responseText,statusText,xhr,$form){ console.log(responseText); // alert(responseText); // $("#contact").toggle('slow'); } </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