001.
<?php
002.
003.
004.
?>
005.
<html>
006.
<head>
007.
<title>ThaiCreate.Com Ajax Tutorial</title>
008.
</head>
009.
<script language=
"JavaScript"
>
010.
var
HttPRequest = false;
011.
012.
function
doCallAjax() {
013.
HttPRequest = false;
014.
if
(window.XMLHttpRequest) {
015.
HttPRequest =
new
XMLHttpRequest();
016.
if
(HttPRequest.overrideMimeType) {
017.
HttPRequest.overrideMimeType(
'text/html'
);
018.
}
019.
}
else
if
(window.ActiveXObject) {
020.
try {
021.
HttPRequest =
new
ActiveXObject(
"Msxml2.XMLHTTP"
);
022.
} catch (e) {
023.
try {
024.
HttPRequest =
new
ActiveXObject(
"Microsoft.XMLHTTP"
);
025.
} catch (e) {}
026.
}
027.
}
028.
029.
if
(!HttPRequest) {
030.
alert(
'Cannot create XMLHTTP instance'
);
031.
return
false;
032.
}
033.
034.
var
url =
'AjaxPHPRegister2.php'
;
035.
var
pmeters =
"tUsername="
+ encodeURI( document.getElementById(
"txtUsername"
).value);
036.
037.
HttPRequest.open(
'POST'
,url,true);
038.
039.
HttPRequest.setRequestHeader(
"Content-type"
,
"application/x-www-form-urlencoded"
);
040.
HttPRequest.setRequestHeader(
"Content-length"
, pmeters.length);
041.
HttPRequest.setRequestHeader(
"Connection"
,
"close"
);
042.
HttPRequest.send(pmeters);
043.
044.
045.
HttPRequest.onreadystatechange =
function
()
046.
{
047.
048.
if
(HttPRequest.readyState == 3)
049.
{
050.
document.getElementById(
"mySpan"
).innerHTML =
".."
;
051.
}
052.
053.
if
(HttPRequest.readyState == 4)
054.
{
055.
if
(HttPRequest.responseText ==
'Y'
)
056.
{
057.
window.location =
'AjaxPHPRegister3.php'
;
058.
}
059.
else
060.
{
061.
document.getElementById(
"mySpan"
).innerHTML = HttPRequest.responseText;
062.
}
063.
}
064.
065.
}
066.
067.
}
068.
</script>
069.
<body>
070.
<h1>Register Form</h1>
071.
<form name=
"frmMain"
>
072.
<table width=
"274"
border=
"1"
>
073.
<tr>
074.
<th width=
"117"
>
075.
<div align=
"left"
>Username</div></th>
076.
<th><div align=
"left"
>
077.
<input type=
"text"
name=
"txtUsername"
id=
"txtUsername"
size=
"20"
OnChange=
"JavaScript:doCallAjax();"
>
078.
<span id=
"mySpan"
></span></div></th>
079.
</tr>
080.
<tr>
081.
<th width=
"117"
>
082.
<div align=
"left"
>Password</div></th>
083.
<th><div align=
"left"
>
084.
<input type=
"password"
name=
"txtPassword"
id=
"txtPassword"
size=
"20"
>
085.
</div></th>
086.
</tr>
087.
<tr>
088.
<th width=
"117"
>
089.
<div align=
"left"
>Name</div></th>
090.
<th><div align=
"left"
>
091.
<input type=
"text"
name=
"txtName"
id=
"txtName"
size=
"20"
>
092.
</div></th>
093.
</tr>
094.
<tr>
095.
<th width=
"117"
>
096.
<div align=
"left"
>Email</div></th>
097.
<th width=
"236"
><div align=
"left"
>
098.
<input type=
"text"
name=
"txtEmail"
id=
"txtEmail"
size=
"20"
>
099.
</div></th>
100.
</tr>
101.
</table>
102.
<br>
103.
<input name=
"btnRegister"
type=
"button"
id=
"btnRegister"
value=
"Register"
>
104.
</form>
105.
</body>
106.
</html>