Last active
August 29, 2015 14:03
-
-
Save jameshibbard/5c9a9b5ec187227267ca to your computer and use it in GitHub Desktop.
Submit whatever value is entered into text field via AJAX
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>AJAX demo</title> | |
</head> | |
<body> | |
<input type="text" id="myTextField" /> | |
<button id="ajax">Submit AJAX request</button> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script> | |
$("#ajax").on("click", function(){ | |
var text = $("#myTextField").text(); | |
$.ajax({ | |
type: "POST", | |
url: "submit.php", | |
cache: false, | |
data: { "value" : text }, | |
success: function(response){ | |
alert("The server says: " + response); | |
}, | |
error: function(response){ | |
alert ("Ajax Error"); | |
console.log(response); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment