xmlh%p
.
onreadystatechange
=
func5on
(){
if (
xmlh%p
.
readyState
==
4
&&
xmlh%p
.
status
==
200
){
}
}
XMLHttpRequest Object
(Properties)
//As the server response is ready now, we can define client actions here.
a=
document
.
getElementById
("result");
a.
innerHTML
=
xmlhttp
.
responseText
;

Example
Application:
Consider implementing a member registration
<form>
. After
the client has entered the user name, we would like to provide immediate
response to the client like
“The name is used by other users.”
or
“You
can use this user name”
before the registration form is submitted
.

<html>
<head>
<script
<!88 Don’t border the JavaScript now, handle that later!!!! 88>
</script>
</head>
<body>
<div
id
="
responseMessage
"></div>
<h1>
Member registra/on
</h1>
<form
acDon
="
memberRegistra/on.php
"
method
="
post
">
User Name
<input
type
="
text
"
id
="
userName
"
name
="
userName
"/> <br />
Password
<input
type
="
password
"
name
="
userPassword
" /> <br />
<input
type
="
submit
" />
</form>
</body>
</html>
Basic HTML code
example.html
bother
>

AJAX for partial update of the page
Step 1. Identify the client event that initiates the request to server.
Define the event handler (a JS function) when the event occurs:

In the event handler, create an
XMLHttpRequest
object:
<script
func%on
valida%on
(){
var
xmlh/p
;
if (window.
XMLH/pRequest
){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlh/p
= new
XMLH/pRequest
();
}else{
// code for IE6, IE5
xmlh/p
= new
Ac%veXObject
("
Microso?.XMLHTTP
");
}
}
</script>
The Javascript code in example.html
AJAX for partial update of the page
>

AJAX for partial update of the page
<script type="text/javascript">
func%on valida%on
(){
var
xmlh/p
;
if (window.
XMLH/pRequest
){ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlh/p
= new
XMLH/pRequest
();
}else{
// code for IE6, IE5
xmlh/p
= new
Ac%veXObject
("
Microso?.XMLHTTP
");
}
xmlh/p
.
onreadystatechange
=
func%on
(){
if (
xmlh/p
.
readyState
==
4
&&
xmlh/p
.
status
==
200
){
}
}
}
</script>
The Javascript code in example.html


You've reached the end of your free preview.
Want to read all 25 pages?
- Fall '13
- Dr. C. Wu
- Ajax