日期:2014-05-16 浏览次数:20358 次
<html>
<head>
<meta charset="utf-8" />
<title>AJAX Login Example</title>
<script src="http://192.168.1.63/common/class_ajax.js"></script>
<script>
// <![CDATA[
window.onload = function()
{
var ajax = new class_ajax();
}
function handle()
{
if (ajax.state == 4)
{
if (ajax.staus == 200)
{
document.write("This is function handle");
}
}
}
function sendmessage()
{
ajax.open("http://192.168.1.63/login/json.txt");
ajax.handle = handle;
ajax.send(NULL);
}
// ]]>
</script>
</head>
<body>
<form>
<input type="button" onsubmit="sendmessage(); return FALSE;" />
</form>
</body>
</html>
function class_ajax()
{
var request;
var browser = navigator.appName;
this.state;
this.status;
this.handle;
this.text;
if(browser != "Microsoft Internet Explorer")
{
request = new XMLHttpRequest();
}else{
var arrVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
for (var i=0; i < arrVersions.length; i++)
{
try
{
request = new ActiveXObject(arrVersions[i]);
}
catch(exception)
{
}
}
}
this.open = function(var url, var method = 0)
{
if (method === 0)
{
return request.open("GET", url, true);
}
else
{
return request.open("POST", url, true);
}
}
this.send = function(var data)
{
return send(data);
}
this.change = function()
{
request.onreadystatechange = onreadystatechange;
}
var onreadystatechange(var state, var handle)
{
this.state = request.readyState;
this.status = request.status;
this.text = request.responseText;
this.handle();
}
}