/* * jQuery PHP Plugin * version: 0.6 (21/11/2008) * author: Anton Shevchuk (http://anton.shevchuk.name) * @requires jQuery v1.2.1 or later * * Examples and documentation at: http://jquery.hohli.com/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id$ */ php = { /** * beforeSend */ beforeSend:function() { return true; }, /** * success * parse AJAX response * @param object response * @param string textStatus */ success:function (response, textStatus) { // call jquery methods for (var i=0;i"; // error report for popup window coocking var printStr = "
"+ "
Error in AJAX request"+ "
»
"+ "
X
"+ "
"+ "
"; printStr += "XMLHttpRequest exchange: "; // XMLHttpRequest.readyState status switch (xmlEr.readyState) { case 0: readyStDesc = "not initialize"; break; case 1: readyStDesc = "open"; break; case 2: readyStDesc = "data transfer"; break; case 3: readyStDesc = "loading"; break; case 4: readyStDesc = "finish"; break; default: return "uncknown state"; } printStr += readyStDesc+" ("+xmlEr.readyState+")"; printStr += "
\n"; if (exObj!=false) { printStr += "exception was catch: "+except.toString(); printStr += "
\n"; } // add http status description printStr += "HTTP status: "+xmlEr.status +" - "+xmlEr.statusText; printStr += "
\n"; // add response text printStr += "Response text (show more information »):"; printStr += "
\n"; printStr += "
"; printStr += "
" ; jQuery(document.body).append(printCss); jQuery(document.body).append(printStr); jQuery('#php-error .php-more').hover( function(){ jQuery(this).css('background-color','#fff') }, function(){ jQuery(this).css('background-color','#fee') }); jQuery('#php-error .php-more').click(function(){ jQuery('#php-error .php-content').slideToggle(); }); jQuery('#php-error .php-more2').click(function(){ jQuery('#php-error .php-content').slideToggle(); return false; }); jQuery('#php-error .php-close').click(function(){ jQuery('#php-error').fadeOut('fast',function(){jQuery('#php-error').remove()}) }); jQuery('#php-error .php-close').hover( function(){ jQuery(this).css('background-color','#fff') }, function(){ jQuery(this).css('background-color','#fee') }); }, /** * complete * * @param object XMLHttpRequest * @param String textStatus */ complete:function(XMLHttpRequest, textStatus) { return true; }, /* Static actions */ /** * addMessage * system messages callback handler * @param object data */ addMessage:function(data) { // call registered or default func var message = data.msg || ""; var callBackFunc = data.callback || "defaultCallBack"; var callBackParams = data.params || {}; php.messages[callBackFunc](message, callBackParams); }, /** * addError * system errors callback handler * @param object data */ addError:function(data) { // call registered or default func var message = data.msg || ""; var callBackFunc = data.callback || "defaultCallBack"; var callBackParams = data.params || {}; php.errors[callBackFunc](message, callBackParams); }, /** * evalScript * @param object data */ evalScript:function(data) { // why foo? var func = data.foo || ''; eval(func); }, /* Default realization of callback functions */ messages : { defaultCallBack : function (msg, params){ alert("Server response message: " + msg); } }, errors : { defaultCallBack : function (msg, params){ alert("Server response error: " + msg); } } }; // end of php actions // example php extension to jQuery (example) jQuery.extend({ php: function (url, params) { // do an ajax post request jQuery.ajax({ // AJAX-specified URL url: url, // JSON type: "POST", data: params, dataType : "json", /* Handlers */ // Handle the beforeSend event beforeSend: function(){ return php.beforeSend(); }, // Handle the success event success: function(data, textStatus){ return php.success(data, textStatus); }, // Handle the error event error: function (xmlEr, typeEr, except) { return php.error(xmlEr, typeEr, except); }, // Handle the complete event complete: function (XMLHttpRequest, textStatus) { return php.complete(XMLHttpRequest, textStatus); } }) } });