To read data on the server:
Html:
<! DOCTYPEHtml>
<Html>
<Head>
<Metacharset="Utf-8" >
<Title>Untitled Document </Title>
<ScriptSrc="Ajax.js" ></Script>
<Script>
Window.OnLoad=function ()
{
VarObtn=document.getElementById (' Btn1 ');
VarOul=document.getElementById (' Ul1 ');
Obtn.onclick=function ()
{
Ajax' Data.txt?t= '+new Date ().GetTime (),function (STR) {
VarArr=EvalSTR);
ForVarI=0;I<Arr.length;I++)
{
VarOLi=document.CreateElement (' Li ');
Oli.innerhtml=' User name:<strong> '+arr[I].user+' </strong> password:<span> '+arr[I].pass+' </span> ';
Oul.AppendChild (OLi);
}
},function () {
Alert' Failure ');
});
};
};
</Script>
</Head>
<body>
<input id="btn1" type= "button" value="read"/>
<ul id="UL1" >
</ul>
</body>
</html>
AJAX,JS:
functionAjaxUrlFNSUCC,Fnfaild)
{
1. Creating an Ajax Object
if (window. XMLHttpRequest)
{
VarOajax=new XMLHttpRequest ();
}
Else
{
VarOajax=newActiveXObject ("Microsoft.XMLHTTP");
}
2. Connecting the server (open and server connections)
Oajax.Open' GET ',Urltrue);
3. Send
Oajax.Send ();
4. Receiving
Oajax.onreadystatechange=function ()
{
if (oajax.readystate= =4)
{
if ( Oajax.status==200)
{
//alert (' succeeded: ' +oajax.responsetext);
fnsucc ( Oajax.responsetext);
}
else
{
if (fnfaild)
{
fnfaild ();
}
}
}
};
} /span>
data.txt:
[{User: ' Blue ', pass: ' 123456 '},{user: ' Zhang San ', pass: ' 654321 '},{user: ' John Doe ', pass: ' 789456 '},{user: ' Harry ', pass: ' 7777 '}]
< Span style= "color: #e6db74; Font-weight:bold; " >
Ajax Knowledge Point supplement