/* * jQuery PHP Plugin * version: 0.8.3 (16/03/2009) * 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$ */ (function($) { $.extend({ php: function (url, params) { // do an ajax post request $.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); } }); } }); 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 += "
" ; $(document.body).append(printCss); $(document.body).append(printStr); $('#php-error .php-more').hover( function(){ $(this).css('background-color','#fff') }, function(){ $(this).css('background-color','#fee') }); $('#php-error .php-more').click(function(){ $('#php-error .php-content').slideToggle(); }); $('#php-error .php-more2').click(function(){ $('#php-error .php-content').slideToggle(); return false; }); $('#php-error .php-close').click(function(){ $('#php-error').fadeOut('fast',function(){$('#php-error').remove()}) }); $('#php-error .php-close').hover( function(){ $(this).css('background-color','#fff') }, function(){ $(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); }, /** * addData * * @param object data */ addData:function(data) { // call registered or default func var callBackFunc = data.callback || "defaultCallBack"; php.data[callBackFunc](data.k, data.v); }, /** * evalScript * @param object data */ evalScript:function(data) { // why foo? var func = data.foo || ''; eval(func); }, /* Default realization of callback functions */ data : { defaultCallBack : function (key, value){ alert("Server response: " + key + " = " + value); } }, messages : { defaultCallBack : function (msg, params){ alert("Server response message: " + msg); } }, errors : { defaultCallBack : function (msg, params){ alert("Server response error: " + msg); } } }; // end of php actions })(jQuery);