Last active
January 6, 2022 16:08
-
-
Save wvpv/c8d868ef4f4efa0045805576bb67387f to your computer and use it in GitHub Desktop.
simple AJAX post example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title></title> | |
<style> | |
table { | |
border-collapse: collapse; | |
} | |
table, th, td { | |
border: 1px solid black; | |
} | |
</style> | |
</head> | |
<body> | |
<form id='form1'> | |
<div><input type='text' name='name' placeholder='Name' /></div> | |
<div><input type='text' name='email' placeholder='Email' /></div> | |
<div><input type='text' name='number' placeholder='Mobile Number' /></div> | |
<div><input type='submit' value='Submit' /></div> | |
</form> | |
<div id='response'></div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js "></script> | |
<script> | |
$(document).ready(function(){ | |
$('#form1').submit(function(){ | |
// show that something is loading | |
$('#response').html("<b>Loading response...</b>"); | |
// Call ajax for pass data to other place | |
$.ajax({ | |
type: 'POST', | |
url: 'YOURCLOUDPAGEURLHERE', | |
data: $(this).serialize() // form values | |
}).done(function(data){ // executed when response is returned | |
// show the response | |
$('#response').html(data); | |
}).fail(function() { // executed when post failed | |
alert( "Submission failed" ); | |
}); | |
// to prevent page refresh | |
return false; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment