[CS-Project-svn_notify] SF.net SVN: cs-project:[1020] trunk/2.0
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-12-16 04:54:00
|
Revision: 1020 http://cs-project.svn.sourceforge.net/cs-project/?rev=1020&view=rev Author: crazedsanity Date: 2009-12-16 04:53:50 +0000 (Wed, 16 Dec 2009) Log Message: ----------- Updated AJAX test. Should be pretty useful for reference. Modified Paths: -------------- trunk/2.0/includes/ajax/test.inc trunk/2.0/public_html/js/ajax.js trunk/2.0/public_html/js/cs-project.js trunk/2.0/templates/content/index.content.tmpl trunk/2.0/templates/main.shared.tmpl Added Paths: ----------- trunk/2.0/public_html/js/webtoolkit.base64.js trunk/2.0/public_html/js/webtoolkit.url.js Modified: trunk/2.0/includes/ajax/test.inc =================================================================== --- trunk/2.0/includes/ajax/test.inc 2009-12-16 01:52:53 UTC (rev 1019) +++ trunk/2.0/includes/ajax/test.inc 2009-12-16 04:53:50 UTC (rev 1020) @@ -10,13 +10,24 @@ * Last Updated:::::::: $Date$ */ -sleep(1); $page->printOnFinish=false; $xml = new cs_phpxmlCreator("ajaxresponse"); + $xml->add_tag("time", microtime()); -$xml->add_tag("callback_success", 'callback_test'); -$xml->add_tag("post_data", htmlentities($page->gfObj->debug_print($_POST,0))); +if($_POST) { + $xml->add_tag("callback_success", 'callback_test'); + $xml->add_tag("post_data", base64_encode($page->gfObj->debug_print($_POST,0))); +} +else { + $xml->add_tag("callback_success", 'callback_get'); + if(count($_GET)) { + foreach($_GET as $gName=>$gVal) { + $xml->add_tag("_get_". $gName, $gVal); + } + $xml->add_tag("all_get_tags", base64_encode($page->gfObj->debug_print($_GET))); + } +} print($xml->create_xml_string()); Modified: trunk/2.0/public_html/js/ajax.js =================================================================== --- trunk/2.0/public_html/js/ajax.js 2009-12-16 01:52:53 UTC (rev 1019) +++ trunk/2.0/public_html/js/ajax.js 2009-12-16 04:53:50 UTC (rev 1020) @@ -31,12 +31,7 @@ cache : false, async : isAsync, dataType : 'text/xml', - success: function (returnXml) { - var xml = parseXML(returnXml); - if($(xml).find('type').text() == 'auth') { - updateLoginBox(xml); - } - }, + success: ajax_successCallback, error: function (returnXml) { alert("Call to " + type + " failed::: " + returnXml); } Modified: trunk/2.0/public_html/js/cs-project.js =================================================================== --- trunk/2.0/public_html/js/cs-project.js 2009-12-16 01:52:53 UTC (rev 1019) +++ trunk/2.0/public_html/js/cs-project.js 2009-12-16 04:53:50 UTC (rev 1020) @@ -29,7 +29,7 @@ //------------------------------------------------------------------------- - function ajax_getTestResponse() { + function ajax_postTestResponse() { myPostData = { @@ -39,6 +39,15 @@ show_ajaxLoading("Checking response..."); ajax_doPost("test", myPostData, "WAIT", "Doing a test POST via AJAX, be patient."); + }//end ajax_postTestResponse() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function ajax_getTestResponse() { + show_ajaxLoading("Sending GET request.."); + ajax_getRequest("test"); }//end ajax_getTestResponse() //------------------------------------------------------------------------- @@ -48,9 +57,19 @@ function callback_test(xmlObj) { $xmlObj = $(xmlObj); updatePageLoadData("Response complete... time was (" + $xmlObj.find("time").text() +")"); - $("#response").html($xmlObj.find("post_data").text()); + $("#response").html(Base64.decode($xmlObj.find("post_data").text())); }//end callback_test() //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function callback_get(xmlObj) { + $xmlObj = $(xmlObj); + updatePageLoadData("GET response complete..."); + $("#getData").html(Base64.decode($xmlObj.find("all_get_tags").text())); + }//end callback_get() + //------------------------------------------------------------------------- /* END AJAX TEST FUNCTIONS */ @@ -60,6 +79,9 @@ $(document).ready(function() { updatePageLoadData("page loaded!"); $("#button1").click(function() { + ajax_postTestResponse(); + }); + $("#button2").click(function() { ajax_getTestResponse(); }); }); Added: trunk/2.0/public_html/js/webtoolkit.base64.js =================================================================== --- trunk/2.0/public_html/js/webtoolkit.base64.js (rev 0) +++ trunk/2.0/public_html/js/webtoolkit.base64.js 2009-12-16 04:53:50 UTC (rev 1020) @@ -0,0 +1,142 @@ +/** +* +* Base64 encode / decode +* http://www.webtoolkit.info/ +* +**/ + +var Base64 = { + + // private property + _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", + + // public method for encoding + encode : function (input) { + var output = ""; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + + input = Base64._utf8_encode(input); + + while (i < input.length) { + + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output = output + + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); + + } + + return output; + }, + + // public method for decoding + decode : function (input) { + var output = ""; + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + + enc1 = this._keyStr.indexOf(input.charAt(i++)); + enc2 = this._keyStr.indexOf(input.charAt(i++)); + enc3 = this._keyStr.indexOf(input.charAt(i++)); + enc4 = this._keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output = output + String.fromCharCode(chr1); + + if (enc3 != 64) { + output = output + String.fromCharCode(chr2); + } + if (enc4 != 64) { + output = output + String.fromCharCode(chr3); + } + + } + + output = Base64._utf8_decode(output); + + return output; + + }, + + // private method for UTF-8 encoding + _utf8_encode : function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }, + + // private method for UTF-8 decoding + _utf8_decode : function (utftext) { + var string = ""; + var i = 0; + var c = c1 = c2 = 0; + + while ( i < utftext.length ) { + + c = utftext.charCodeAt(i); + + if (c < 128) { + string += String.fromCharCode(c); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + + } + + return string; + } + +} Added: trunk/2.0/public_html/js/webtoolkit.url.js =================================================================== --- trunk/2.0/public_html/js/webtoolkit.url.js (rev 0) +++ trunk/2.0/public_html/js/webtoolkit.url.js 2009-12-16 04:53:50 UTC (rev 1020) @@ -0,0 +1,78 @@ +/** +* +* URL encode / decode +* http://www.webtoolkit.info/ +* +**/ + +var Url = { + + // public method for url encoding + encode : function (string) { + return escape(this._utf8_encode(string)); + }, + + // public method for url decoding + decode : function (string) { + return this._utf8_decode(unescape(string)); + }, + + // private method for UTF-8 encoding + _utf8_encode : function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }, + + // private method for UTF-8 decoding + _utf8_decode : function (utftext) { + var string = ""; + var i = 0; + var c = c1 = c2 = 0; + + while ( i < utftext.length ) { + + c = utftext.charCodeAt(i); + + if (c < 128) { + string += String.fromCharCode(c); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + + } + + return string; + } + +} \ No newline at end of file Modified: trunk/2.0/templates/content/index.content.tmpl =================================================================== --- trunk/2.0/templates/content/index.content.tmpl 2009-12-16 01:52:53 UTC (rev 1019) +++ trunk/2.0/templates/content/index.content.tmpl 2009-12-16 04:53:50 UTC (rev 1020) @@ -5,10 +5,19 @@ so you can watch the data being sent.</p> <form> - <input type="button" id="button1" value="Click me"/> + <input type="button" id="button1" value="POST Test"/> + <input type="button" id="button2" value="GET Test" /> </form> +<div id="pageLoadData" style="border:solid #000 1px;">This gets updated once the page is completely loaded.</div> +<table border="1" width="80%" align="center"> + <tr> + <th width="50%">POST Stuff:</th> + <th width="50%">GET Stuff:</th> + </tr> + <tr> + <td id="response">No data yet... CLICK THE BUTTON!!!</td> + <td id="getData" style="border:solid #000 1px;">Click the "GET TEST" button!</td> + </tr> +</table> -<div id="pageLoadData" style="border:solid #000 1px;">This gets updated once the page is completely loaded.</div> - -<div id="response">No data yet... CLICK THE BUTTON!!!</div> Modified: trunk/2.0/templates/main.shared.tmpl =================================================================== --- trunk/2.0/templates/main.shared.tmpl 2009-12-16 01:52:53 UTC (rev 1019) +++ trunk/2.0/templates/main.shared.tmpl 2009-12-16 04:53:50 UTC (rev 1020) @@ -5,6 +5,8 @@ <link rel="stylesheet" href="/css/crazed.css" type="text/css"> <script language="javascript" src="/js/jquery-1.3.2.min.js" type="text/javascript"></script> <script language="javascript" src="/js/jquery.blockUI.js" type="text/javascript"></script> +<script language="javascript" src="/js/webtoolkit.url.js" type="text/javascript"></script> +<script language="javascript" src="/js/webtoolkit.base64.js" type="text/javascript"></script> <script language="javascript" src="/js/ajax.js" type="text/javascript"></script> <script language="javascript" src="/js/cs-project.js" type="text/javascript"></script> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |