Skip to content

Instantly share code, notes, and snippets.

@CVertex
Forked from anonymous/FreeCourseGuideAjax.html
Last active December 22, 2015 17:59
Show Gist options
  • Save CVertex/6509828 to your computer and use it in GitHub Desktop.
Save CVertex/6509828 to your computer and use it in GitHub Desktop.
<form action="#" id="courseGuideForm" method="post">
<input type="hidden" name="X-Requested-With" value="XMLHttpRequest" />
<input type="text" name="Name" value="" />
<input type="text" name="Email" value="" />
<input type="button" class="submitButton" value="Get Your Guide Now" />
</form>
<script type="text/javascript">
$(function () {
jQuery('#courseGuideForm .submitButton').click(function () {
// Do validation on the name
// then on the email
// if all good, ajax post
console.log("submit form");
$.post('/Home/FreeCourseGuide', // URL
{ Name: "Vijay Santhanam", Email: "[email protected]", "X-Requested-With": "XMLHttpRequest" }, // DATA
function (data, textStatus) {
console.log(textStatus);
console.log(data);
});
/*
$('#courseGuideForm').ajaxForm(function (result) {
console.log(result);
alert('form successfully submitted');
return false;
});
*/
//return false;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment