<s>
XMLHttpRequest	B-Protocol
(	O
XHR	B-Protocol
)	O
is	O
a	O
JavaScript	B-Language
class	O
containing	O
methods	B-Language
to	O
asynchronously	O
transmit	O
HTTP	B-Protocol
requests	I-Protocol
from	O
a	O
web	B-Application
browser	I-Application
to	O
a	O
web	B-Application
server	I-Application
.	O
</s>
<s>
The	O
methods	B-Language
allow	O
a	O
browser-based	O
application	O
to	O
make	O
a	O
fine-grained	O
server	O
call	O
and	O
store	O
the	O
results	O
in	O
XMLHttpRequest	B-Protocol
's	O
responseText	O
attribute	B-General_Concept
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
class	O
is	O
a	O
component	O
of	O
Ajax	B-General_Concept
programming	I-General_Concept
.	O
</s>
<s>
Prior	O
to	O
Ajax	B-General_Concept
,	O
a	O
HTML	B-General_Concept
form	I-General_Concept
needed	O
to	O
be	O
completely	O
sent	O
to	O
the	O
server	O
followed	O
by	O
a	O
complete	O
browser	B-Application
page	O
refresh	O
.	O
</s>
<s>
The	O
concept	O
behind	O
the	O
XMLHttpRequest	B-Protocol
class	O
was	O
conceived	O
in	O
2000	O
by	O
the	O
developers	O
of	O
Microsoft	B-Application
Outlook	I-Application
--	O
available	O
on	O
the	O
Windows	B-Application
2000	I-Application
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
The	O
concept	O
was	O
then	O
implemented	O
within	O
the	O
Internet	B-Protocol
Explorer	I-Protocol
5	I-Protocol
(	O
2001	O
)	O
browser	B-Application
's	O
interpreter	B-Application
.	O
</s>
<s>
However	O
,	O
the	O
original	O
syntax	O
did	O
not	O
use	O
the	O
XMLHttpRequest	B-Protocol
identifier	O
.	O
</s>
<s>
Instead	O
,	O
the	O
developers	O
used	O
the	O
identifiers	O
ActiveXObject( 	O
"	O
Msxml2.XMLHTTP	O
"	O
)	O
and	O
ActiveXObject( 	O
"	O
Microsoft.XMLHTTP	O
"	O
)	O
.	O
</s>
<s>
As	O
of	O
Internet	B-Application
Explorer	I-Application
7	I-Application
(	O
2006	O
)	O
,	O
all	O
browsers	B-Application
support	O
the	O
XMLHttpRequest	B-Protocol
identifier	O
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
identifier	O
is	O
now	O
the	O
de	O
facto	O
standard	O
in	O
all	O
the	O
major	O
browsers	B-Application
,	O
including	O
Mozilla	B-Operating_System
's	I-Operating_System
Gecko	B-Language
layout	I-Language
engine	I-Language
(	O
2002	O
)	O
,	O
Konqueror	B-Application
(	O
2002	O
)	O
,	O
Safari	B-Application
1.2	O
(	O
2004	O
)	O
,	O
Opera	B-Application
8.0	O
(	O
2005	O
)	O
,,	O
and	O
iCab	B-Operating_System
(	O
2005	O
)	O
.	O
</s>
<s>
With	O
the	O
advent	O
of	O
cross-browser	O
JavaScript	B-Language
libraries	O
such	O
as	O
jQuery	B-Language
,	O
developers	O
can	O
invoke	O
XMLHttpRequest	B-Protocol
functionality	O
indirectly	O
.	O
</s>
<s>
The	O
World	O
Wide	O
Web	O
Consortium	O
(	O
WC3	O
)	O
published	O
a	O
Working	O
Draft	O
specification	O
for	O
the	O
XMLHttpRequest	B-Protocol
object	O
on	O
April	O
5	O
,	O
2006	O
.	O
</s>
<s>
Level	O
2	O
added	O
methods	B-Language
to	O
monitor	O
event	O
progress	O
,	O
allow	O
cross-site	O
requests	O
,	O
and	O
handle	O
byte	O
streams	O
.	O
</s>
<s>
At	O
the	O
end	O
of	O
2012	O
,	O
the	O
WHATWG	B-Language
took	O
over	O
development	O
and	O
maintains	O
a	O
living	O
document	O
using	O
Web	B-Protocol
IDL	I-Protocol
.	O
</s>
<s>
Generating	O
an	O
asynchronous	O
request	O
to	O
the	O
web	B-Application
server	I-Application
requires	O
first	O
to	O
instantiate	O
(	O
allocate	O
the	O
memory	O
of	O
)	O
the	O
XMLHttpRequest	B-Protocol
object	O
.	O
</s>
<s>
The	O
programming	O
statement	O
in	O
JavaScript	B-Language
to	O
instantiate	O
a	O
new	O
object	O
is	O
new	O
.	O
</s>
<s>
The	O
custom	O
for	O
object-oriented	B-Language
language	I-Language
developers	O
is	O
to	O
invoke	O
the	O
constructor	O
function	O
using	O
same	O
name	O
as	O
the	O
class	O
name	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
class	O
name	O
is	O
XMLHttpRequest	B-Protocol
.	O
</s>
<s>
To	O
instantiate	O
a	O
new	O
XMLHttpRequest	B-Protocol
and	O
assign	O
it	O
to	O
the	O
variable	O
named	O
request	O
:	O
</s>
<s>
var	O
request	O
=	O
new	O
XMLHttpRequest( )	O
;	O
</s>
<s>
The	O
open	O
method	O
prepares	O
the	O
XMLHttpRequest	B-Protocol
.	O
</s>
<s>
var	O
request	O
=	O
new	O
XMLHttpRequest( )	O
;	O
</s>
<s>
RequestMethod	O
:	O
The	O
HTTP	B-Protocol
request	O
method	O
may	O
be	O
GET	O
for	O
typical	O
quantities	O
of	O
data	O
.	O
</s>
<s>
Among	O
the	O
other	O
request	O
methods	B-Language
available	O
,	O
POST	B-Protocol
will	O
handle	O
substantial	O
quantities	O
of	O
data	O
.	O
</s>
<s>
After	O
the	O
return	O
string	O
is	O
received	O
,	O
then	O
send	O
the	O
DELETE	O
request	O
method	O
to	O
.open( )	O
to	O
free	O
the	O
XMLHttpRequest	B-Protocol
memory	O
.	O
</s>
<s>
SubmitURL	O
:	O
The	O
SubmitURL	O
is	O
a	O
URL	O
containing	O
the	O
execution	B-General_Concept
filename	B-Device
and	O
any	O
parameters	O
that	O
get	O
submitted	O
to	O
the	O
web	B-Application
server	I-Application
.	O
</s>
<s>
If	O
the	O
URL	O
contains	O
the	O
host	B-Device
name	I-Device
,	O
it	O
must	O
be	O
the	O
web	B-Application
server	I-Application
that	O
sent	O
the	O
HTML	B-Language
document	O
.	O
</s>
<s>
Ajax	B-General_Concept
supports	O
the	O
same-origin	B-Protocol
policy	I-Protocol
.	O
</s>
<s>
If	O
set	O
to	O
false	O
,	O
then	O
the	O
browser	B-Application
will	O
wait	O
until	O
the	O
return	O
string	O
is	O
received	O
.	O
</s>
<s>
Programmers	O
are	O
discouraged	O
to	O
set	O
AsynchronousBoolean	O
to	O
false	O
,	O
and	O
browsers	B-Application
may	O
experience	O
an	O
exception	O
error	O
.	O
</s>
<s>
If	O
the	O
request	O
method	O
of	O
POST	B-Protocol
is	O
invoked	O
,	O
then	O
the	O
additional	O
step	O
of	O
sending	O
the	O
media	B-Application
type	I-Application
of	O
Content-Type	B-Application
:	O
application/x	O
-www-form-urlencoded	O
is	O
required	O
.	O
</s>
<s>
The	O
setRequestHeader	O
method	O
allows	O
the	O
program	O
to	O
send	O
this	O
or	O
other	O
HTTP	B-Protocol
headers	I-Protocol
to	O
the	O
web	B-Application
server	I-Application
.	O
</s>
<s>
To	O
enable	O
the	O
POST	B-Protocol
request	I-Protocol
method	O
:	O
</s>
<s>
</s>
<s>
If	O
the	O
request	O
method	O
of	O
POST	B-Protocol
is	O
invoked	O
,	O
then	O
the	O
web	B-Application
server	I-Application
expects	O
the	O
form	B-General_Concept
data	I-General_Concept
to	O
be	O
read	O
from	O
the	O
standard	O
input	O
stream	O
.	O
</s>
<s>
To	O
send	O
the	O
form	B-General_Concept
data	I-General_Concept
to	O
the	O
web	B-Application
server	I-Application
,	O
execute	O
request.send( FormData )	O
,	O
where	O
FormData	O
is	O
a	O
text	O
string	O
.	O
</s>
<s>
If	O
the	O
request	O
method	O
of	O
GET	O
is	O
invoked	O
,	O
then	O
the	O
web	B-Application
server	I-Application
expects	O
only	O
the	O
default	O
headers	O
.	O
</s>
<s>
onreadystatechange	O
is	O
a	O
callback	O
method	O
that	O
is	O
periodically	O
executed	O
throughout	O
the	O
Ajax	B-General_Concept
lifecycle	O
.	O
</s>
<s>
For	O
convenience	O
,	O
the	O
syntax	O
allows	O
for	O
an	O
anonymous	B-General_Concept
method	I-General_Concept
to	O
be	O
defined	O
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
lifecycle	O
progresses	O
through	O
several	O
stages	O
--	O
from	O
0	O
to	O
4	O
.	O
</s>
<s>
To	O
monitor	O
the	O
lifecycle	O
,	O
XMLHttpRequest	B-Protocol
has	O
available	O
the	O
readyState	O
attribute	B-General_Concept
.	O
</s>
<s>
Stages	O
1-3	O
are	O
ambiguous	O
and	O
interpretations	O
vary	O
across	O
browsers	B-Application
.	O
</s>
<s>
When	O
readyState	O
reaches	O
4	O
,	O
then	O
the	O
text	O
string	O
has	O
arrived	O
and	O
is	O
set	O
in	O
the	O
responseText	O
attribute	B-General_Concept
.	O
</s>
<s>
Upon	O
request	O
,	O
the	O
browser	B-Application
will	O
execute	O
a	O
JavaScript	B-Language
function	O
to	O
transmit	O
a	O
request	O
for	O
the	O
web	B-Application
server	I-Application
to	O
execute	O
a	O
computer	B-Application
program	I-Application
.	O
</s>
<s>
The	O
computer	B-Application
program	I-Application
may	O
be	O
the	O
PHP	B-Application
interpreter	I-Application
,	O
another	O
interpreter	B-Application
,	O
or	O
a	O
compiled	B-Language
executable	B-Application
.	O
</s>
<s>
In	O
any	O
case	O
,	O
the	O
JavaScript	B-Language
function	O
expects	O
a	O
text	O
string	O
to	O
be	O
transmitted	O
back	O
and	O
stored	O
in	O
the	O
responseText	O
attribute	B-General_Concept
.	O
</s>
<s>
To	O
create	O
an	O
example	O
JavaScript	B-Language
function	O
:	O
</s>
<s>
PHP	B-Application
is	O
a	O
scripting	B-Language
language	I-Language
designed	O
specifically	O
to	O
interface	B-Application
with	O
HTML	B-Language
.	O
</s>
<s>
Because	O
the	O
PHP	B-Application
engine	O
is	O
an	O
interpreter	B-Application
--	O
interpreting	O
program	O
statements	O
as	O
they	O
are	O
read	O
--	O
there	O
are	O
programming	O
limitations	O
and	O
performance	O
costs	O
.	O
</s>
<s>
Nonetheless	O
,	O
its	O
simplicity	O
may	O
place	O
the	O
XMLHttpRequest	B-Protocol
set	O
of	O
files	O
in	O
the	O
same	O
working	O
directory	O
--	O
probably	O
/var/www/html	O
.	O
</s>
<s>
The	O
server	O
component	O
of	O
a	O
PHP	B-Application
XMLHttpRequest	B-Protocol
is	O
a	O
file	O
located	O
on	O
the	O
server	O
that	O
does	O
n't	O
get	O
transmitted	O
to	O
the	O
browser	B-Application
.	O
</s>
<s>
Instead	O
,	O
the	O
PHP	B-Application
interpreter	I-Application
will	O
open	O
this	O
file	O
and	O
read	O
in	O
its	O
PHP	B-Application
instructions	O
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
protocol	O
requires	O
it	O
to	O
output	O
a	O
text	O
string	O
.	O
</s>
<s>
Edit	O
a	O
file	O
named	O
ajax.phtml	O
:	O
</s>
<s>
The	O
browser	B-Application
component	O
of	O
a	O
PHP	B-Application
XMLHttpRequest	B-Protocol
is	O
a	O
file	O
located	O
on	O
the	O
server	O
that	O
gets	O
transmitted	O
to	O
the	O
browser	B-Application
.	O
</s>
<s>
The	O
browser	B-Application
will	O
open	O
this	O
file	O
and	O
read	O
in	O
its	O
HTML	B-Language
instructions	O
.	O
</s>
<s>
Edit	O
a	O
file	O
named	O
ajax.html	O
:	O
</s>
<s>
The	O
Common	B-Language
Gateway	I-Language
Interface	I-Language
(	O
CGI	O
)	O
process	O
allows	O
browsers	B-Application
to	O
request	O
the	O
web	B-Application
server	I-Application
to	O
execute	O
compiled	B-Language
computer	B-Application
programs	I-Application
.	O
</s>
<s>
The	O
server	O
component	O
of	O
a	O
CGI	O
XMLHttpRequest	B-Protocol
is	O
an	O
executable	B-Application
file	I-Application
located	O
on	O
the	O
server	O
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
will	O
open	O
this	O
file	O
and	O
read	O
in	O
its	O
machine	B-Language
instructions	I-Language
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
protocol	O
requires	O
the	O
executable	B-Application
to	O
output	O
a	O
text	O
string	O
.	O
</s>
<s>
Compiled	B-Language
programs	O
have	O
two	O
files	O
:	O
the	O
source	O
code	O
and	O
a	O
corresponding	O
executable	B-Application
.	O
</s>
<s>
Edit	O
a	O
file	O
named	O
ajax.c	O
:	O
</s>
<s>
Compile	B-Language
the	O
source	O
code	O
to	O
create	O
the	O
executable	B-Application
:	O
</s>
<s>
The	O
CGI	O
browser	B-Application
component	O
is	O
the	O
same	O
as	O
the	O
PHP	B-Application
browser	B-Application
component	O
,	O
except	O
for	O
a	O
slight	O
change	O
in	O
the	O
submit_url	O
.	O
</s>
<s>
The	O
syntax	O
to	O
tell	O
the	O
web	B-Application
server	I-Application
to	O
execute	O
an	O
executable	B-Application
is	O
/cgi-bin/	O
followed	O
by	O
the	O
filename	B-Device
.	O
</s>
<s>
For	O
security	O
,	O
the	O
executable	B-Application
must	O
reside	O
in	O
a	O
chroot	B-Application
jail	I-Application
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
jail	O
is	O
the	O
directory	O
/usr/lib/cgi-bin/	O
.	O
</s>
<s>
Edit	O
a	O
file	O
named	O
ajax.html	O
:	O
</s>
