ตัวอย่าง AJAX
ที่จะช่วยให้คุณเข้าใจ AJAX ทำงานเราสร้างโปรแกรมประยุกต์ AJAX ขนาดเล็ก:
ตัวอย่าง AJAX ของการวิเคราะห์
การประยุกต์ใช้ AJAX ดังกล่าวข้างต้นมี div และปุ่ม
ส่วน div สำหรับการแสดงข้อมูลจากเซิร์ฟเวอร์ เมื่อมีการคลิกปุ่มก็มีหน้าที่ในการเรียกฟังก์ชั่นชื่อ loadXMLDoc () เป็น:
<!DOCTYPE html>
<html>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
<html>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
ถัดไปในส่วนหัวของหน้าเพื่อเพิ่ม <script> แท็ก ฉลากมี loadXMLDoc () ฟังก์ชัน:
<head>
<script>
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>
<script>
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>
ส่วนต่อไปนี้จะอธิบายผลงาน AJAX ของคุณ