Skip to content

Instantly share code, notes, and snippets.

@videlais
Created May 12, 2019 00:09
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 videlais/30beda9ccd2bab0c3632f40309e9b45a to your computer and use it in GitHub Desktop.
Save videlais/30beda9ccd2bab0c3632f40309e9b45a to your computer and use it in GitHub Desktop.
jQuery + AJAX + PHP: Part 1: Getting a Response
<html>
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<title>jQuery + AJAX + PHP: Part 1: Getting a Response</title>
</head>
<body>
<div id="log"></div>
<script>
$.ajax({
method: "POST",
url: "response.php",
data: { name: "Dan", example: "Yup" }
})
.done(function( message ) {
$("#log").text(message);
})
.fail(function( message ) {
$("#log").text(message);
});
</script>
</body>
</html>
<?php
echo "Received " . $_REQUEST['name'];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment