Snippets > jQuery Ajax


#html#javascript#jquery#php

Ajax with jQuery and PHP.

ajax.html
<html>
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
	<script>
		$(function() {
		
			$('#ajax-test').click(function () {
				
				$.ajax({
					url: 'ajax.php',
					success: function(result) {
						$('#ajax-result').val(result);
					}
				});
				
			});
			
		});
	</script>
</head>
<body>
    <form>
		<input type="button" id="ajax-test" value="Ajax Test"> <input type="text" id="ajax-result">
	</form>
</body>
</html>

ajax.php

echo "Ajax result";