// Ajax request
Function Ajax (method, URL ){
This. method = method;
This. url = URL;
Ajax. Counter ++;
}
Ajax. Counter = 0;
Ajax. Prototype. createxhr = function () {// create XMLHttpRequest
VaR xmlhttp_request = "";
Try {
If (window. activexobject ){
For (VAR I = 5; I --){
Try {
If (I = 2 ){
Xmlhttp_request = new activexobject ('Microsoft. xmlhttp ');
}
Else {
Xmlhttp_request = new activexobject ('msxml2. XMLHTTP. '+ I +'. 0 ');
Xmlhttp_request.setrequestheader ('content-type', 'text/xml ');
Xmlhttp_request.setrequestheader ('charset', 'gb2312 ');
}
Break;
}
Catch (e ){
Xmlhttp_request = false;
}
}
}
Else if (window. XMLHttpRequest ){
Xmlhttp_request = new XMLHttpRequest ();
}
}
Catch (e) {xmlhttp_request = false ;}
Return xmlhttp_request;
}
Ajax. Prototype. encodeuri = function (_ URL ){
VaR Pos = _ URL. indexof ('? '),
HTTP = '',
ARGs = '';
If (Pos! =-1 ){
HTTP = _ URL. substring (0, POS + 1 );
ARGs = _ URL. substring (Pos + 1 );
VaR hash = args. Split ('&');
For (VAR I = 0; I Pos = hash [I]. indexof ('= ');
If (Pos! =-1 ){
Hash [I] = hash [I]. substring (0, POS + 1) + encodeuricomponent (hash [I]. substring (Pos + 1 ));
}
}
}
Else {
Return _ URL;
}
Return HTTP + hash. Join ('&');
}
Ajax. Prototype. callajax = function (senderobjid ){
VaR xmlhttp_request = This. createxhr ();
If (! Xmlhttp_request ){
Alert ('your browser does not support Ajax. ');
Return;
}
If (this. Method = 'get '){
Xmlhttp_request.open (this. method, this. encodeuri (this. url), true );
Xmlhttp_request.send (null );
VaR self = xmlhttp_request; // assign the reference to the temporary variable self
VaR objid = senderobjid; // The control that triggers
Xmlhttp_request.onreadystatechange = function (){
Thecallback (self, objid );
};
}
Else {
Throw new error ('ajax has not implemented a non-"get" transfer method. ');
}
}
Page:
VaR Ajax = new Ajax ('get', '../handler/selectdept. aspx? Parent = 01 & temp = '+ new date (). getmilliseconds ());
Ajax. callaajax (senderobjid );
......
Function thecallback (xmlhttp_request, senderobjid ){
VaR result = xmlhttp_request.readystate;
Switch (result ){
Case 0:
Case 1:
Case 2:
Case 3: break;
// A pop-up window should be displayed to indicate that the user is loading data.
......
Case 4:
// Getobj (senderobjid). removeattribute ('Disabled ');
// The pop-up window should be deleted here
If (xmlhttp_request.status = 200 ){
// Debugger;
// Bindhandler (Ajax. Counter, senderobjid); bind the event Method to the DOM
......
}
Else {
Alert ('request error. Error code: '+ xmlhttp_request.status );
Return;
}
Break;
Default: Alert ('xmlhttprequest returns a value that exceeds expectation. ');
Break;
}
}