Introduction
A simple ajax class to use. Design for ie and firefox. It just use to send data and receive it, and deal with the data yourself.
Background
I just write it suit my design.
Using the code
Now, this is the code.
Blocks of code should be set as style "Formatted"
like this:
var AjaxKtClass = function()
{
this.xmlHttp = false;
this.url = "";
this.updateFun = null;
this.Create = function(url, updateFun)
{
if(!this.xmlHttp&&typeof XMLHttpRequest != 'undefined'){
this.xmlHttp = new XMLHttpRequest();
}
this.url = url;
this.updateFun = updateFun;
}
this.Open = function()
{
this.xmlHttp.open("GET", this.url, true);
this.xmlHttp.onreadystatechange = this.updateFun;
this.xmlHttp.send(null);
}
this.Open2 = function(url)
{
this.xmlHttp.open("GET", url, true);
this.xmlHttp.onreadystatechange = this.updateFun;
this.xmlHttp.send(null);
}
this.Open3 = function(param)
{
this.xmlHttp.open("GET", this.url + param, true);
this.xmlHttp.onreadystatechange = this.updateFun;
this.xmlHttp.send(null);
}
this.GetData = function()
{
if(this.xmlHttp.readyState == 4){
return this.xmlHttp.responseText;
}
return null;
}
}
Use it:
<script language="javascript">
var ajaxObj = new AjaxKtClass();
ajaxObj.Create("progress.html", AjaxAct);
function AjaxAct()
{
var ret = ajaxObj.GetData();
if(ret == null) return;
if(ret=="OK")
{
}
}
function Send()
{
ajaxObj.Open();
}
</script>
Points of Interest
If you interest it, please emailt to me: stephen_liang@163.com
History
Keep a running update of any changes or improvements you've
made here.