Create a gist now

Instantly share code, notes, and snippets.

Submit whatever value is entered into text field via AJAX
<!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