Skip to content

Instantly share code, notes, and snippets.

@wvpv
Last active January 6, 2022 16:08
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 wvpv/c8d868ef4f4efa0045805576bb67387f to your computer and use it in GitHub Desktop.
Save wvpv/c8d868ef4f4efa0045805576bb67387f to your computer and use it in GitHub Desktop.
simple AJAX post example
<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