Skip to content

Instantly share code, notes, and snippets.

@philipmorg
Last active December 22, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipmorg/6418376 to your computer and use it in GitHub Desktop.
Save philipmorg/6418376 to your computer and use it in GitHub Desktop.
What I want to happen is for #cta-div to be populated with the "Thank you! We will be..." message if the form POST does not timeout or have some other kind of error. What is actually happening is that #cta-div is being populated with "Sorry, our system..." even if the form POST is successful. What do I change to get my desired behavior?
<form action="{{ form-action }}" method="post" class="pure-form" id="become-lead">
<fieldset class="pure-group">
<input type='text' name="lead[name]" placeholder='Your full name' class="pure-input-1" required/>
<input type='text' name="lead[phone]" placeholder='Your phone number' class="pure-input-1" required />
<input type='text' name="lead[email]" placeholder='Your email address' class="pure-input-1" required />
</fieldset>
<input type='text' name="note[content]" placeholder='{{ signup-loc }}' default='{{ signup-loc }}' value='{{ signup-loc }}' style="display:none;" />
<button type="submit" class="pure-button pure-button-success">Contact Me About Enrollment</button>
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#become-lead").submit(function() {
//Do the AJAX post
$.ajax({
type: "POST",
url: $("#become-lead").attr("action"),
data: $("#become-lead").serialize(),
dataType: "json",
success: function() {
$("#cta-div").html('<h2 class="hdg hdg_2 skinny-line-spacing">Thank you! We will be in touch very soon.</h3>');
//alert("success");
console.log(status);
},
error: function() {
//something went wrong, check err and status
$("#cta-div").html('<h2 class="hdg hdg_2 skinny-line-spacing">Thank you! We will be in touch very soon.</h3>');
//$("#cta-div").html('<h2 class="hdg hdg_2 skinny-line-spacing">Sorry, our system is having problems! Please call 415.665.6988 to register.</h3>');
//alert("error");
console.log(status);
}
});
//Important. Stop the normal POST
return false;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment