The code is very concise, here is not much nonsense, directly on the source
HTML code
Copy Code code as follows:
<!doctype html>
<meta charset= "Utf-8"/>
<body>
<button type= "button" onclick= "Show ()" > Request data </button>
<script src= "Ajax.js" ></script>
<script>
Function Show () {
Ajax (' read.txt?datetime=new date.gettime ', function (str) {alert (str);},function () {alert (' failed ');})
};
</script>
</body>
JavaScript code
Copy Code code as follows:
function Ajax (url,fnsucc,fnfaild)
{
1. Creating Ajax Objects
if (window. XMLHttpRequest)
{//code for ie7+, Firefox, Chrome, Opera, Safari
var oajax=new xmlhttprequest ();
}
Else
{//code for IE6, IE5
var oajax=new activexobject ("Microsoft.XMLHTTP");
}
2. Linked server (open server connection)
Open (method, filename, asynchronous transmission)
Oajax.open (' Get ', url,true);
3. Send
Oajax.send ();
4. Receive return
Oajax.onreadystatechange=function ()
{
if (oajax.readystate==4)
{
if (oajax.status==200)
{
FNSUCC (Oajax.responsetext);
}
Else
{
Fnfaild (Oajax.status);
}
};
};
}
The requested file is Read.txt
Fill in the content casually