Ajax
An Ajax class
function Ajax (URL,RECVT,STRINGS,RESULTF) {
This.url = URL;
This.strings = StringS;
This.xmlhttp = This.createxmlhttprequest ();
if (this.xmlhttp = = null) {
Alert ("Erro");
Return
}
var objxml = this.xmlhttp;
Objxml.onreadystatechange = function () {Ajax.handlestatechange (OBJXML,RECVT,RESULTF)};
}
Ajax.prototype.createXMLHttpRequest = function () {
try {return new ActiveXObject ("Msxml2.xmlhttp"); catch (e) {}
try {return new ActiveXObject ("Microsoft.XMLHTTP");} catch (e) {}
try {return new XMLHttpRequest (); catch (e) {}
return null;
}
Ajax.prototype.createQueryString = function () {
var querystring = this.strings;
return querystring;
}
Ajax.prototype.get = function () {
url = this.url;
var querystring = url+ "? timestamp=" + New Date (). GetTime () + "&" + this.createquerystring ();
This.xmlHttp.open ("Get", querystring,true);
This.xmlHttp.send (NULL);
}
Ajax.prototype.post = function () {
url = this.url;
var url = url + "? timestamp=" + New Date (). GetTime ();
var querystring = this.createquerystring ();
this.xmlHttp.open ("POST", url,true);
this.xmlHttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded");
This.xmlHttp.send (querystring);
}
Ajax.handlestatechange = function (XMLHTTP,RECVT,RESULTF) {
if (xmlhttp.readystate = 4) {
if (xmlhttp.status = =) {
RESULTF (Recvt?xmlhttp.responsexml:xmlhttp.responsetext);
} else {
alert (" The page you are requesting has an exception. ");
}
}
}
How to use
var classajax = new Ajax (URL,RECVT,STRINGS,RESULTF);
Classajax.post (); Send data in//post mode
Classajax.get (); Send data in//get mode
URL send address recvt accept data type 0 FOR XML 1 for text RESULTF return result handler
Cases
var ajax1 = new Ajax ("1.asp", 0, "id=" +id,bacal);
Ajax1.post ();
function Bacal (REXM) {
Returns the data processing function;
}
-----------------------------------------------------------
Quertion:
One of the code RESULTF (Recvt?xmlhttp.responsexml:xmlhttp.responsetext);
Do not understand, there is the eldest brother to explain the explanation?
When RECVT is 0 o'clock, it returns an object, I don't know how to use it, or what attribute does the object have?
The middle of this sentence? And: What's the format here, what role?
Answer:
Ternary operator.
(a>b)? 1:0
It means: If a>b, then 1 or 0.
RESULTF (Recvt?xmlhttp.responsexml:xmlhttp.responsetext);
by literal means:
Accept data function: RESULTF
Data received: RECVT (should be abbreviated as recived text)
The returned data is returned in Xmlhttp.responsexml or Xmlhttp.responsetext format.