写一个html请求ajax的代码
时间: 2024-05-20 08:17:41 浏览: 83
C# 中做生成ajax的html代码
<!DOCTYPE html>
<html>
<head>
<title>AJAX Request</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn-ajax").click(function(){
$.ajax({
url: "ajax.php",
type: "POST",
data: {name: "John", age: "25"},
success: function(result){
$("#ajax-response").html(result);
}
});
});
});
</script>
</head>
<body>
<button id="btn-ajax">Make AJAX Request</button>
<div id="ajax-response"></div>
</body>
</html>
<!-- ajax.php -->
<?php
$name = $_POST['name'];
$age = $_POST['age'];
echo "Hello, my name is $name and I am $age years old.";
?>
阅读全文