Created
May 27, 2016 09:27
-
-
Save wolendranh/13af8ba71a468b28b42d5c7c779798ed to your computer and use it in GitHub Desktop.
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> | |
<script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<form id="simple-form"> | |
<input type="text" name="answer" value="insert your value here"> | |
<p><input type="submit"></p> | |
</form> | |
<script type="text/javascript"> | |
$("#simple-form").submit(function(e) { | |
var url = "google.com"; // url where data should be posted | |
$.ajax({ | |
type: "POST", | |
url: url, | |
data: $("#simple-form").serialize(), // serializes the form's elements. | |
success: function(data) // success handler | |
{ | |
alert(data); | |
}, | |
error: function(data) // success handler | |
{ | |
console.log(data); | |
} | |
}); | |
e.preventDefault(); // avoid to execute the actual submit of the form. | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment