<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Ajax Hello World </title>
<Script language = "JavaScript" type = "text/JavaScript">
/*
VaR DATA = {'website': ['moreyin. com', '51js. com', 'phpchina. com'],
'Category': ['website builder', 'script programming BBS ', 'php BBS']};
Alert (data. website [0]);
*/
</SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
Function startrequest (){
Createxmlhttprequest ();
Try {
XMLHTTP. onreadystatechange = handlestatechange;
XMLHTTP. Open ("get", "data.txt", true );
XMLHTTP. Send (null );
} Catch (exception ){
Alert ("The resource you want to access does not exist! ");
}
}
Function handlestatechange (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 | XMLHTTP. Status = 0 ){
// Obtain the returned string
VaR resp = XMLHTTP. responsetext;
// Construct a method for returning a JSON object
// Function indicates that this is an object. Return + resp indicates that the object is constructed using a string.
VaR func = new function ("return" + resp );
// You can also use eval to define objects.
// Eval ("Var JSON =" + resp );
// Obtain the JSON object
VaR JSON = func ();
// Display the returned results
Alert ("JSON's value:" + json.info + "(" + JSON. Version + "V )");
}
}
}
</SCRIPT>
</Head>
<Body>
<Div>
<Input type = "button" value = "Return Ajax JSON's value"
Onclick = "startrequest ();"/>
</Div>
</Body>
</Html>