diff -uNr sajax-0.11/Changes.txt sajax-0.12/Changes.txt
--- sajax-0.11/Changes.txt Tue Apr 12 12:17:15 2005
+++ sajax-0.12/Changes.txt Mon Jan 30 02:52:25 2006
@@ -1,6 +1,12 @@
SAJAX CHANGELOG
---------------
+Sajax version 0.12 (January 30, 2006)
+
+* [php] Numerous improvements to serialization, support for varied PHP
+ setups, addition of sajax_cancel().
+* [asp] Removed due to serious bugs
+
Sajax version 0.10 (March 21, 2005)
* [php] Support for POST instead of just GET. Set $sajax_request_type.
diff -uNr sajax-0.11/asp/Readme.txt sajax-0.12/asp/Readme.txt
--- sajax-0.11/asp/Readme.txt Tue Apr 12 12:17:15 2005
+++ sajax-0.12/asp/Readme.txt Mon Jan 30 02:40:26 2006
@@ -1,4 +1,3 @@
-SAJAX ASP(JScript) BACKEND
---------------------------
+ASP support has been temporarily removed due to bugs. It will be back soon.
-Contributed and copyighted by Jared Nuzzolillo (http://www.protoscript.net/).
+- tlack
diff -uNr sajax-0.11/asp/example_multiply.asp sajax-0.12/asp/example_multiply.asp
--- sajax-0.11/asp/example_multiply.asp Tue Apr 12 12:17:15 2005
+++ sajax-0.12/asp/example_multiply.asp Wed Dec 31 19:00:00 1969
@@ -1,77 +0,0 @@
-<%@ Language=JScript %>
-
-
-<%
-
- function multiply(x, y) {
- return x * y;
- }
-
- function add(x, y, z) {
- return x + y + z;
- }
-
- sajax = new Sajax();
-// sajax.debug_mode = true;
- sajax.export_function("multiply","add");
- sajax.handle_client_request();
-
-%>
-
-
- Multiplier
-
-
-
-
- *
-
- =
-
-
-
- try adding some strings, eg:
-
- +
-
- +
-
- =
-
-
-
-
diff -uNr sajax-0.11/asp/sajax.asp sajax-0.12/asp/sajax.asp
--- sajax-0.11/asp/sajax.asp Tue Apr 12 12:17:15 2005
+++ sajax-0.12/asp/sajax.asp Wed Dec 31 19:00:00 1969
@@ -1,186 +0,0 @@
-<%
-
-function r(str)
-{
- Response.write("
-"+str+"-
")
-}
-
- function Sajax(debug_mode)
- {
- this.debug_mode = debug_mode||false;
- this.export_list = [];
- this.js_has_been_shown = false;
-
- this.handle_client_request = function()
- {
- func_name = Request.QueryString("rs");
- if(!func_name||String(func_name)=="undefined") return false
-
- //bust cache
- Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT")
- //always modified
- Response.AddHeader("Last-Modified", new Date().toGMTString().replace(/UTC/,"GMT"))
- //HTTP/1.1
- Response.AddHeader("Cache-Control", "no-cache, must-revalidate")
- //HTTP/1.0
- Response.AddHeader("Pragma", "no-cache")
-
-
-
- if(this.export_list[func_name]=="undefined")
- {
- result = "-"+func_name+" is not callable";
- //if(this.debug_mode) Response.write("-"+func_name+" is not callable");
- }
- else
- {
- rsargs_raw = Request.QueryString("rsargs[]")
-
- rsargs = []
- for(rs_i=1;rs_i<=rsargs_raw.Count;rs_i++)
- {
- rsargs[rs_i-1]=rsargs_raw(rs_i)
- }
-
- // if(this.debug_mode) Response.write("calling " + func_name + "(" +
- // rsargs.join(",")+")")
-
- eval_str = this.export_list[func_name]+"("+rsargs+")"
-
- try
- {
- result = "+"+eval(eval_str);
- }
- catch(e)
- {
- result = "-"+e.message+" (x_"+eval_str+")";
- }
- }
-
- Response.write(result+"[sajax_result________end]]")
- //exit()
- }
-
- this.show_common_js = function()
- {
- js_debug_mode = this.debug_mode
- js_string_out = " // remote scripting library\n" +
- " // (c) copyright 2005 modernmethod, inc\n" +
- " var rs_debug_mode = "+js_debug_mode+";\n" +
- " var rs_obj = false;\n" +
- " var rs_callback = false;\n" +
- " \n" +
- " function rs_debug(text) {\n" +
- " if (rs_debug_mode)\n" +
- " alert('RSD: ' + text)\n" +
- " }\n" +
- " \n" +
- " function rs_init_object() {\n" +
- " rs_debug('rs_init_object() called..')\n" +
- " \n" +
- " var A;\n" +
- " try {\n" +
- " A=new ActiveXObject('Msxml2.XMLHTTP');\n" +
- " } catch (e) {\n" +
- " try {\n" +
- " A=new ActiveXObject('Microsoft.XMLHTTP');\n" +
- " } catch (oc) {\n" +
- " A=null;\n" +
- " }\n" +
- " }\n" +
- " if(!A && typeof XMLHttpRequest != 'undefined')\n" +
- " A = new XMLHttpRequest();\n" +
- " if (!A)\n" +
- " rs_debug('Could not create connection object.');\n" +
- " return A;\n" +
- " }\n"
-
- Response.write(js_string_out)
- }
-
- this.rs_esc=function(val)
- {
-
- }
-
- this.export_function = function()
- {
- for(var i=0;i-1))
- {
- uri += "?rs=" + escape(func_name)
- }
- else
- {
- uri += "&rs=" + escape(func_name)
- }
-
- escapeduri = this.rs_esc(uri)
- js_string_out = " // wrapper for "+func_name+"\n" +
- " function x_"+func_name+"(){\n" +
- " // count args; build URL\n" +
- " var i, x, n;\n" +
- " //var url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" +
- " url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" +
- " for (i = 0; i < a.length-1; i++)\n" +
- " url = url + '&rsargs[]=' + escape(a[i]);\n" +
- " x = rs_init_object();\n" +
- " x.open('GET', url, true);\n" +
- " x.onreadystatechange = function() {\n" +
- " if (x.readyState != 4)\n" +
- " return;\n" +
- " rs_debug('received ' + x.responseText);\n" +
- " \n" +
- " var status;\n" +
- " var data;\n" +
- " status = x.responseText.charAt(0);\n" +
- " data = x.responseText;\n" +
- " var pos = data.indexOf('[sajax_result________end]]');\n " +
- " if (status == '-'){\n" +
- " if("+this.debug_mode+"){alert('Error: ' + data.substring(1,pos));}}\n" +
- " else \n" +
- " a[a.length-1](data.substring(1,pos));\n" +
- " }\n" +
- " x.send(null);\n" +
- " rs_debug('x_"+func_name+" url = ' + url);\n" +
- " rs_debug('x_"+func_name+" waiting..');\n" +
- " }\n"
-
- Response.write(js_string_out)
- }
- }
-%>
\ No newline at end of file
diff -uNr sajax-0.11/php/Sajax.php sajax-0.12/php/Sajax.php
--- sajax-0.11/php/Sajax.php Tue Apr 12 15:43:34 2005
+++ sajax-0.12/php/Sajax.php Mon Jan 30 02:56:28 2006
@@ -5,10 +5,12 @@
* GLOBALS AND DEFAULTS
*
*/
- $sajax_debug_mode = 0;
- $sajax_export_list = array();
- $sajax_request_type = "GET";
- $sajax_remote_uri = "";
+ $GLOBALS['sajax_version'] = '0.12';
+ $GLOBALS['sajax_debug_mode'] = 0;
+ $GLOBALS['sajax_export_list'] = array();
+ $GLOBALS['sajax_request_type'] = 'GET';
+ $GLOBALS['sajax_remote_uri'] = '';
+ $GLOBALS['sajax_failure_redirect'] = '';
/*
* CODE
@@ -25,9 +27,7 @@
// Helper function to return the script's own URI.
//
function sajax_get_my_uri() {
- global $REQUEST_URI;
-
- return $REQUEST_URI;
+ return $_SERVER["REQUEST_URI"];
}
$sajax_remote_uri = sajax_get_my_uri();
@@ -38,8 +38,10 @@
function sajax_get_js_repr($value) {
$type = gettype($value);
- if ($type == "boolean" ||
- $type == "integer") {
+ if ($type == "boolean") {
+ return ($value) ? "Boolean(true)" : "Boolean(false)";
+ }
+ elseif ($type == "integer") {
return "parseInt($value)";
}
elseif ($type == "double") {
@@ -62,11 +64,13 @@
else
$s .= "\"$esc_key\": " . sajax_get_js_repr($v) . ", ";
}
- return substr($s, 0, -2) . " }";
+ if (count($value))
+ $s = substr($s, 0, -2);
+ return $s . " }";
}
else {
$esc_val = sajax_esc($value);
- $s = "\"$esc_val\"";
+ $s = "'$esc_val'";
return $s;
}
}
@@ -113,7 +117,7 @@
else {
echo "+:";
$result = call_user_func_array($func_name, $args);
- echo "var res = " . sajax_get_js_repr($result) . "; res;";
+ echo "var res = " . trim(sajax_get_js_repr($result)) . "; res;";
}
exit;
}
@@ -122,6 +126,7 @@
global $sajax_debug_mode;
global $sajax_request_type;
global $sajax_remote_uri;
+ global $sajax_failure_redirect;
$t = strtoupper($sajax_request_type);
if ($t != "" && $t != "GET" && $t != "POST")
@@ -135,30 +140,46 @@
var sajax_debug_mode = ;
var sajax_request_type = "";
var sajax_target_id = "";
+ var sajax_failure_redirect = "";
function sajax_debug(text) {
if (sajax_debug_mode)
- alert("RSD: " + text)
+ alert(text);
}
+
function sajax_init_object() {
sajax_debug("sajax_init_object() called..")
var A;
- try {
- A=new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
+
+ var msxmlhttp = new Array(
+ 'Msxml2.XMLHTTP.5.0',
+ 'Msxml2.XMLHTTP.4.0',
+ 'Msxml2.XMLHTTP.3.0',
+ 'Msxml2.XMLHTTP',
+ 'Microsoft.XMLHTTP');
+ for (var i = 0; i < msxmlhttp.length; i++) {
try {
- A=new ActiveXObject("Microsoft.XMLHTTP");
- } catch (oc) {
- A=null;
+ A = new ActiveXObject(msxmlhttp[i]);
+ } catch (e) {
+ A = null;
}
}
+
if(!A && typeof XMLHttpRequest != "undefined")
A = new XMLHttpRequest();
if (!A)
sajax_debug("Could not create connection object.");
return A;
}
+
+ var sajax_requests = new Array();
+
+ function sajax_cancel() {
+ for (var i = 0; i < sajax_requests.length; i++)
+ sajax_requests[i].abort();
+ }
+
function sajax_do_call(func_name, args) {
var i, x, n;
var uri;
@@ -167,7 +188,7 @@
sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
target_id = sajax_target_id;
- if (sajax_request_type == "")
+ if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "")
sajax_request_type = "GET";
uri = "";
@@ -198,32 +219,63 @@
}
x = sajax_init_object();
- x.open(sajax_request_type, uri, true);
-
- if (sajax_request_type == "POST") {
- x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
- x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- }
+ if (x == null) {
+ if (sajax_failure_redirect != "") {
+ location.href = sajax_failure_redirect;
+ return false;
+ } else {
+ sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent);
+ return false;
+ }
+ } else {
+ x.open(sajax_request_type, uri, true);
+ // window.open(uri);
+
+ sajax_requests[sajax_requests.length] = x;
+
+ if (sajax_request_type == "POST") {
+ x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
+ x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
- x.onreadystatechange = function() {
- if (x.readyState != 4)
- return;
+ x.onreadystatechange = function() {
+ if (x.readyState != 4)
+ return;
- sajax_debug("received " + x.responseText);
+ sajax_debug("received " + x.responseText);
- var status;
- var data;
- status = x.responseText.charAt(0);
- data = x.responseText.substring(2);
- if (status == "-")
- alert("Error: " + data);
- else {
- if (target_id != "")
- document.getElementById(target_id).innerHTML = eval(data);
- else
- args[args.length-1](eval(data));
+ var status;
+ var data;
+ var txt = x.responseText.replace(/^\s*|\s*$/g,"");
+ status = txt.charAt(0);
+ data = txt.substring(2);
+
+ if (status == "") {
+ // let's just assume this is a pre-response bailout and let it slide for now
+ } else if (status == "-")
+ alert("Error: " + data);
+ else {
+ if (target_id != "")
+ document.getElementById(target_id).innerHTML = eval(data);
+ else {
+ try {
+ var callback;
+ var extra_data = false;
+ if (typeof args[args.length-1] == "object") {
+ callback = args[args.length-1].callback;
+ extra_data = args[args.length-1].extra_data;
+ } else {
+ callback = args[args.length-1];
+ }
+ callback(eval(data), extra_data);
+ } catch (e) {
+ sajax_debug("Caught error " + e + ": Could not eval " + data );
+ }
+ }
+ }
}
}
+
sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
x.send(post_data);
sajax_debug(func_name + " waiting..");
@@ -247,6 +299,7 @@
$val = str_replace("\\", "\\\\", $val);
$val = str_replace("\r", "\\r", $val);
$val = str_replace("\n", "\\n", $val);
+ $val = str_replace("'", "\\'", $val);
return str_replace('"', '\\"', $val);
}
diff -uNr sajax-0.11/php/Sajax.php.txt sajax-0.12/php/Sajax.php.txt
--- sajax-0.11/php/Sajax.php.txt Tue Apr 12 15:43:34 2005
+++ sajax-0.12/php/Sajax.php.txt Mon Jan 30 02:56:28 2006
@@ -5,10 +5,12 @@
* GLOBALS AND DEFAULTS
*
*/
- $sajax_debug_mode = 0;
- $sajax_export_list = array();
- $sajax_request_type = "GET";
- $sajax_remote_uri = "";
+ $GLOBALS['sajax_version'] = '0.12';
+ $GLOBALS['sajax_debug_mode'] = 0;
+ $GLOBALS['sajax_export_list'] = array();
+ $GLOBALS['sajax_request_type'] = 'GET';
+ $GLOBALS['sajax_remote_uri'] = '';
+ $GLOBALS['sajax_failure_redirect'] = '';
/*
* CODE
@@ -25,9 +27,7 @@
// Helper function to return the script's own URI.
//
function sajax_get_my_uri() {
- global $REQUEST_URI;
-
- return $REQUEST_URI;
+ return $_SERVER["REQUEST_URI"];
}
$sajax_remote_uri = sajax_get_my_uri();
@@ -38,8 +38,10 @@
function sajax_get_js_repr($value) {
$type = gettype($value);
- if ($type == "boolean" ||
- $type == "integer") {
+ if ($type == "boolean") {
+ return ($value) ? "Boolean(true)" : "Boolean(false)";
+ }
+ elseif ($type == "integer") {
return "parseInt($value)";
}
elseif ($type == "double") {
@@ -62,11 +64,13 @@
else
$s .= "\"$esc_key\": " . sajax_get_js_repr($v) . ", ";
}
- return substr($s, 0, -2) . " }";
+ if (count($value))
+ $s = substr($s, 0, -2);
+ return $s . " }";
}
else {
$esc_val = sajax_esc($value);
- $s = "\"$esc_val\"";
+ $s = "'$esc_val'";
return $s;
}
}
@@ -113,7 +117,7 @@
else {
echo "+:";
$result = call_user_func_array($func_name, $args);
- echo "var res = " . sajax_get_js_repr($result) . "; res;";
+ echo "var res = " . trim(sajax_get_js_repr($result)) . "; res;";
}
exit;
}
@@ -122,6 +126,7 @@
global $sajax_debug_mode;
global $sajax_request_type;
global $sajax_remote_uri;
+ global $sajax_failure_redirect;
$t = strtoupper($sajax_request_type);
if ($t != "" && $t != "GET" && $t != "POST")
@@ -135,30 +140,46 @@
var sajax_debug_mode = ;
var sajax_request_type = "";
var sajax_target_id = "";
+ var sajax_failure_redirect = "";
function sajax_debug(text) {
if (sajax_debug_mode)
- alert("RSD: " + text)
+ alert(text);
}
+
function sajax_init_object() {
sajax_debug("sajax_init_object() called..")
var A;
- try {
- A=new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
+
+ var msxmlhttp = new Array(
+ 'Msxml2.XMLHTTP.5.0',
+ 'Msxml2.XMLHTTP.4.0',
+ 'Msxml2.XMLHTTP.3.0',
+ 'Msxml2.XMLHTTP',
+ 'Microsoft.XMLHTTP');
+ for (var i = 0; i < msxmlhttp.length; i++) {
try {
- A=new ActiveXObject("Microsoft.XMLHTTP");
- } catch (oc) {
- A=null;
+ A = new ActiveXObject(msxmlhttp[i]);
+ } catch (e) {
+ A = null;
}
}
+
if(!A && typeof XMLHttpRequest != "undefined")
A = new XMLHttpRequest();
if (!A)
sajax_debug("Could not create connection object.");
return A;
}
+
+ var sajax_requests = new Array();
+
+ function sajax_cancel() {
+ for (var i = 0; i < sajax_requests.length; i++)
+ sajax_requests[i].abort();
+ }
+
function sajax_do_call(func_name, args) {
var i, x, n;
var uri;
@@ -167,7 +188,7 @@
sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
target_id = sajax_target_id;
- if (sajax_request_type == "")
+ if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "")
sajax_request_type = "GET";
uri = "";
@@ -198,32 +219,63 @@
}
x = sajax_init_object();
- x.open(sajax_request_type, uri, true);
-
- if (sajax_request_type == "POST") {
- x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
- x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- }
+ if (x == null) {
+ if (sajax_failure_redirect != "") {
+ location.href = sajax_failure_redirect;
+ return false;
+ } else {
+ sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent);
+ return false;
+ }
+ } else {
+ x.open(sajax_request_type, uri, true);
+ // window.open(uri);
+
+ sajax_requests[sajax_requests.length] = x;
+
+ if (sajax_request_type == "POST") {
+ x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
+ x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
- x.onreadystatechange = function() {
- if (x.readyState != 4)
- return;
+ x.onreadystatechange = function() {
+ if (x.readyState != 4)
+ return;
- sajax_debug("received " + x.responseText);
+ sajax_debug("received " + x.responseText);
- var status;
- var data;
- status = x.responseText.charAt(0);
- data = x.responseText.substring(2);
- if (status == "-")
- alert("Error: " + data);
- else {
- if (target_id != "")
- document.getElementById(target_id).innerHTML = eval(data);
- else
- args[args.length-1](eval(data));
+ var status;
+ var data;
+ var txt = x.responseText.replace(/^\s*|\s*$/g,"");
+ status = txt.charAt(0);
+ data = txt.substring(2);
+
+ if (status == "") {
+ // let's just assume this is a pre-response bailout and let it slide for now
+ } else if (status == "-")
+ alert("Error: " + data);
+ else {
+ if (target_id != "")
+ document.getElementById(target_id).innerHTML = eval(data);
+ else {
+ try {
+ var callback;
+ var extra_data = false;
+ if (typeof args[args.length-1] == "object") {
+ callback = args[args.length-1].callback;
+ extra_data = args[args.length-1].extra_data;
+ } else {
+ callback = args[args.length-1];
+ }
+ callback(eval(data), extra_data);
+ } catch (e) {
+ sajax_debug("Caught error " + e + ": Could not eval " + data );
+ }
+ }
+ }
}
}
+
sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
x.send(post_data);
sajax_debug(func_name + " waiting..");
@@ -247,6 +299,7 @@
$val = str_replace("\\", "\\\\", $val);
$val = str_replace("\r", "\\r", $val);
$val = str_replace("\n", "\\n", $val);
+ $val = str_replace("'", "\\'", $val);
return str_replace('"', '\\"', $val);
}
diff -uNr sajax-0.11/php/example_wall.php sajax-0.12/php/example_wall.php
--- sajax-0.11/php/example_wall.php Tue Apr 12 16:30:51 2005
+++ sajax-0.12/php/example_wall.php Mon Jan 30 02:56:59 2006
@@ -1,9 +1,8 @@
-
- require("Sajax.php");
-
+
@@ -90,9 +88,8 @@