Skip to content

Instantly share code, notes, and snippets.

@videlais
Created May 12, 2019 00:09
Embed
What would you like to do?
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