1 // remote scripting library
2 // (c) copyright 2005 modernmethod, inc
3 var sajax_debug_mode
= false;
4 var sajax_request_type
= "GET";
6 function sajax_debug(text
) {
11 function sajax_init_object() {
12 sajax_debug("sajax_init_object() called..")
15 A
=new ActiveXObject("Msxml2.XMLHTTP");
18 A
=new ActiveXObject("Microsoft.XMLHTTP");
23 if(!A
&& typeof XMLHttpRequest
!= "undefined")
24 A
= new XMLHttpRequest();
26 sajax_debug("Could not create connection object.");
31 function sajax_do_call(func_name
, args
) {
35 uri
= wgServer
+ "/" + wgScriptPath
+ "/index.php?action=ajax";
36 if (sajax_request_type
== "GET") {
37 if (uri
.indexOf("?") == -1)
38 uri
= uri
+ "?rs=" + escape(func_name
);
40 uri
= uri
+ "&rs=" + escape(func_name
);
41 for (i
= 0; i
< args
.length
-1; i
++)
42 uri
= uri
+ "&rsargs[]=" + escape(args
[i
]);
43 //uri = uri + "&rsrnd=" + new Date().getTime();
46 post_data
= "rs=" + escape(func_name
);
47 for (i
= 0; i
< args
.length
-1; i
++)
48 post_data
= post_data
+ "&rsargs[]=" + escape(args
[i
]);
50 x
= sajax_init_object();
51 x
.open(sajax_request_type
, uri
, true);
52 if (sajax_request_type
== "POST") {
53 x
.setRequestHeader("Method", "POST " + uri
+ " HTTP/1.1");
54 x
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
56 x
.setRequestHeader("Pragma", "cache=yes");
57 x
.setRequestHeader("Cache-Control", "no-transform");
58 x
.onreadystatechange = function() {
59 if (x
.readyState
!= 4)
61 sajax_debug("received " + x
.responseText
);
64 status
= x
.responseText
.charAt(0);
65 data
= x
.responseText
.substring(2);
67 alert("Error: " + data
);
69 args
[args
.length
-1](data
);
72 sajax_debug(func_name
+ " uri = " + uri
+ "/post = " + post_data
);
73 sajax_debug(func_name
+ " waiting..");