下面的示例使用jQuery$.get()方法使用HTTP GET方法向“ date-time.php”文件发出Ajax请求。它只是检索从服务器返回的日期和时间,并在浏览器中显示它而无需刷新页面。
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery get() Demo</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.get("date-time.php", function(data){
// Display the returned data in browser
$("#result").html(data);
});
});
});
</script>
</head>
<body>
<div id="result">
<h2>Content of the result DIV box will be replaced by the server date and time</h2>
</div>
<button type="button">Load Date and Time</button>
</body>
</html>
如果您觉得本文的内容对您的学习有所帮助:
关键字:
html