1.function Ajax ()
2.{
3. var len=arguments.length;
4. var type,url,postdata,fn;
5. if (LEN<2)
6. {
7. Alert (' No overload of 2 parameters, at least must specify the request type (type) and URL address! ');
8. return;
9.}
Type=arguments[0];
URL=ARGUMENTS[1];
if (len>2)
13. {
var args=arguments[2];
if (typeof (args) = = "string")
16. {
Postdata=args;
18.}
19.}
var xhr = window. ActiveXObject? New ActiveXObject ("Microsoft.XMLHTTP"): New XMLHttpRequest ();
Xhr.open (type,url,true);
Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
fn = arguments[len-1];
Xhr.onreadystatechange = function () {
if (xhr.readystate==4)
26. {
if (xhr.status==200)
28. {
if (typeof (fn) = = "function")
FN (Xhr.responsetext);
31.}
. else
33. {
Alert ("The page you requested has an exception");
35.}
36.}
37.};
Xhr.send (PostData);
39.}
40.
A. function Test ()
42. {
Ajax ("Get", "/webroot/servlet/testajax");
Ajax ("Get", "/webroot/servlet/testajax", function (date) {
-Alert ("Get date:\n" +date);
46.});
Ajax ("Post", "/webroot/servlet/testajax");
Ajax ("Post", "/webroot/servlet/testajax", function (date) {
Alert ("Post date:\n" +date);
50.});
I Ajax ("Post", "/webroot/servlet/testajax", "username=jonllen&pwd=12345 6", function (date) {
Alert ("Post date:\n" +date);
53.});
54.}