<html> <head> <title>ThaiCreate.Com Ajax Tutorial</title> </head> <script language="JavaScript"> var HttPRequest = false; function doCallAjax(url) { HttPRequest = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... HttPRequest = new XMLHttpRequest(); if (HttPRequest.overrideMimeType) { HttPRequest.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { HttPRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { HttPRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!HttPRequest) { alert('Cannot create XMLHTTP instance'); return false; } HttPRequest.open('POST',url,true); HttPRequest.send(null); HttPRequest.onreadystatechange = function() { if(HttPRequest.readyState == 3) // Loading Request { document.getElementById("mySpan").innerHTML = "Now is Loading..."; } alert('Please see at web page status = '+HttPRequest.readyState); if(HttPRequest.readyState == 4) // Return Request { document.getElementById("mySpan").innerHTML = HttPRequest.responseText; } } /* HttPRequest.onreadystatechange = call function .... // Call other function */ } </script> <body> <span id="mySpan"></span> <input name="btnButton" id="btnButton" type="button" value="Click" onClick="JavaScript:doCallAjax('hello.php');"> </body> </html>
<?php /*** By Weerachai Nukitram ***/ /*** http://www.ThaiCreate.Com ***/ for($i=1;$i<=5;$i++) { echo "Hello ThaiCreate.Com <br>"; } ?>
<% '*** By Weerachai Nukitram ***' '*** http://www.ThaiCreate.Com ***' Dim i For i = 1 To 5 Response.write("Hello ThaiCreate.Com <br>") Next %>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท