Click here to Skip to main content
14,096,273 members
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 21 Dec 2007
Licenced CPOL

A simple ajax class to use

, 21 Dec 2007
Rate this:
Please Sign up or sign in to vote.
Design a simple to use ajax, for ie,firefox


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.


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:

// JavaScript Document
 *  Ajax Class
 *  Designer:	Stephen Liang
var AjaxKtClass = function()
	this.xmlHttp = false;
	this.url = "";
	this.updateFun = null;

	this.Create = function(url, updateFun)
		/*@cc_on @*/
		/*@if(@_jscript_version >= 5)
			this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				this.xmlHttp = false;
		@end @*/
		if(!this.xmlHttp&&typeof XMLHttpRequest != 'undefined'){
			this.xmlHttp = new XMLHttpRequest();
		this.url = url;
		this.updateFun = updateFun;

	this.Open = function()
	{"GET", this.url, true);
		this.xmlHttp.onreadystatechange = this.updateFun;
	this.Open2 = function(url)
	{"GET", url, true);
		this.xmlHttp.onreadystatechange = this.updateFun;
	this.Open3 = function(param)
	{"GET", this.url + param, true);
		this.xmlHttp.onreadystatechange = this.updateFun;
	this.GetData = function()
		if(this.xmlHttp.readyState == 4){
			return this.xmlHttp.responseText;
		return null;

Use it:
<script language="javascript">
// Ajax Object
var ajaxObj = new AjaxKtClass();
ajaxObj.Create("progress.html", AjaxAct);

// Ajax act function
function AjaxAct()
	var ret = ajaxObj.GetData();
	if(ret == null) return;
        // Your progress here

// Ajax send function
function Send()
//or like these

Points of Interest

If you interest it, please emailt to me:


Keep a running update of any changes or improvements you've made here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

General还不错 Pin
kyle198310-Mar-10 20:11
memberkyle198310-Mar-10 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190518.1 | Last Updated 22 Dec 2007
Article Copyright 2007 by Stephen Liang
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid