/** * php actions */ php = { /** * beforeSend */ beforeSend:function() { return true; }, /** * success * parse AJAX response * @param object response */ success:function (response, textStatus) { // call jquery methods for (var i=0;i"; if (exObj!=false) { printStr += "exception was catch: "+except.toString()+"
"; } // add http status description printStr += "
HTTP status:
"+xmlEr.status +" - "+xmlEr.statusText+"

"; // add response text printStr += "Response text :
"+ xmlEr.responseText ; var mywin = window.open( "", "","status=0,width=500,height=600, resizable = yes ,scrollbars = yes ",true); mywin.document.clear(); mywin.document.write(printStr); mywin.document.close(); }, /** * 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 (params) { // do an ajax post request $.ajax({ // AJAX-specified URL url: "http://"+document.domain+"/try/jquery-php-2008-01-09/ajax.php", // 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); } }) } }); // example registering simple callback function for messages php.messages.myCallBack = function (msg, params){ alert ("My messages CallBack func: " + msg); } // example registering simple callback function for errors php.errors.myCallBack = function (msg, params){ alert ("My errors CallBack func: " + msg); }