ajax_queue.js {PARTE 2} Código PHP:
c_ajax_object.prototype.CallXMLHTTPObjectPOSTParam = function ( in_url, in_callback, in_param ) {
return this.CallXMLHTTPObject ( in_url, in_callback, "POST", in_param, null, 0 );
}
c_ajax_object.prototype.CallXMLHTTPObjectPOSTParamPartial = function ( in_url, in_callback, in_param, in_pcallback, in_param2 ) {
return this.CallXMLHTTPObject ( in_url, in_callback, "POST", in_param, in_pcallback, in_param2, 0 );
}
c_ajax_object.prototype.CallXMLHTTPObjectPOSTParamPartialPhase = function ( in_url, in_callback, in_param, in_pcallback, in_param2, in_phase ) {
return this.CallXMLHTTPObject ( in_url, in_callback, "POST", in_param, in_pcallback, in_param2, in_phase );
}
c_ajax_object.prototype.CallXMLHTTPObject = function ( in_url, in_callback, in_method, in_param, in_pcallback, in_param2, in_phase ) {
this._dm_pre_queue_in_url=in_url;
this._dm_pre_queue_in_callback=in_callback;
this._dm_pre_queue_in_method=in_method;
this._dm_pre_queue_in_param=in_param;
this._dm_pre_queue_in_pcallback=in_pcallback;
this._dm_pre_queue_in_param2=in_param2;
this._dm_pre_queue_in_c2_phase=in_phase;
if ( (this._dm_pre_queue_in_c2_phase < 1) || (this._dm_pre_queue_in_c2_phase > 3) ) {
this._dm_pre_queue_in_c2_phase = 3;
}
this.Enqueue();
return true;
};
c_ajax_object.prototype.Enqueue = function ( ) {
this._dm_queue[this._dm_queue.length] = new Array ( this._dm_pre_queue_in_url, this._dm_pre_queue_in_callback,
this._dm_pre_queue_in_method, this._dm_pre_queue_in_param, this._dm_pre_queue_in_pcallback,
this._dm_pre_queue_in_param2, this._dm_pre_queue_in_c2_phase );
this._dm_pre_queue_in_url=null;
this._dm_pre_queue_in_callback=null;
this._dm_pre_queue_in_method=null;
this._dm_pre_queue_in_param=null;
this._dm_pre_queue_in_pcallback=null;
this._dm_pre_queue_in_param2=null;
this._dm_pre_queue_in_c2_phase=0;
if ( !this._dm_xmlhttprequestobject ) {
this.Dequeue();
}
};
c_ajax_object.prototype.Dequeue = function ( ) {
var command = null;
var ret=false;
if ( this._dm_queue.length && this._dm_queue_state ) {
command = this._dm_queue[0];
var url = command[0];
this._dm_callback_function = command[1];
var method = command[2];
this._dm_param = command[3];
this._dm_partialcallback_function = command[4];
this._dm_param2 = command[5];
this._dm_phase = command[6];
for ( var counter = 1; counter < this._dm_queue.length; counter++ ) {
this._dm_queue[counter - 1] = this._dm_queue[counter];
}
this._dm_queue.length = counter - 1;
}
if ( url && method ) {
ret = this._CallXMLHTTPObject ( url, method );
}
return ret;
};
c_ajax_object.prototype._CallXMLHTTPObject = function ( in_url, in_method ) {
try {
var sVars = null;
if ( in_method == "POST" ) {
var rmatch = /^([^?]*)?(.*)$/.exec ( in_url );
in_url = rmatch[1];
sVars = unescape ( rmatch[2] );
}
this._dm_committed = false;
this.GetNewRequestObject();
this._dm_xmlhttprequestobject.open(in_method, in_url, true);
if ( in_method == "POST" ) {
this._dm_xmlhttprequestobject.setRequestHeader("Method", "POST "+in_url+" HTTP/1.1");
this._dm_xmlhttprequestobject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
this._dm_xmlhttprequestobject.onreadystatechange = Handle_HTTP_Response;
this._dm_xmlhttprequestobject.send(sVars);
return true;
}
catch ( z ) { }
return false;
};
function Handle_HTTP_Response () {
var ie = navigator.appName=='Microsoft Internet Explorer';
if ( g_ajax_obj && g_ajax_obj._dm_xmlhttprequestobject ) {
if ( g_ajax_obj._dm_xmlhttprequestobject.readyState == 0 ) {
}
else {
if ( g_ajax_obj._dm_xmlhttprequestobject.readyState == 1 ) {
if ( g_ajax_obj._dm_phase == g_ajax_obj._dm_xmlhttprequestobject.readyState ) {
if ( g_ajax_obj._dm_partialcallback_function ) {
var resp;
if(!ie && g_ajax_obj._dm_xmlhttprequestobject.responseText){
resp=g_ajax_obj._dm_xmlhttprequestobject.responseText;
}
g_ajax_obj._dm_partialcallback_function ( resp, g_ajax_obj._dm_param2 ? g_ajax_obj._dm_param2 : g_ajax_obj._dm_param );
}
}
}
else {
if ( g_ajax_obj._dm_xmlhttprequestobject.readyState == 2 ) {
if ( g_ajax_obj._dm_phase == g_ajax_obj._dm_xmlhttprequestobject.readyState ) {
if ( g_ajax_obj._dm_partialcallback_function ) {
var resp;
if(!ie && g_ajax_obj._dm_xmlhttprequestobject.responseText){
resp=g_ajax_obj._dm_xmlhttprequestobject.responseText;
}
g_ajax_obj._dm_partialcallback_function ( resp, g_ajax_obj._dm_param2 ? g_ajax_obj._dm_param2 : g_ajax_obj._dm_param );
}
}
}
else {
if ( g_ajax_obj._dm_xmlhttprequestobject.readyState == 3 ) { // Interactive
g_ajax_obj._dm_committed = true;
if ( g_ajax_obj._dm_phase == g_ajax_obj._dm_xmlhttprequestobject.readyState ) {
if ( g_ajax_obj._dm_partialcallback_function ) {
var resp;
if(!ie && g_ajax_obj._dm_xmlhttprequestobject.responseText){
resp=g_ajax_obj._dm_xmlhttprequestobject.responseText;
}
g_ajax_obj._dm_partialcallback_function ( resp, g_ajax_obj._dm_param2 ? g_ajax_obj._dm_param2 : g_ajax_obj._dm_param );
}
}
}
else {
if ( g_ajax_obj._dm_xmlhttprequestobject.readyState == 4 ) { // We're done. Back to you.
g_ajax_obj._dm_callback_function ( g_ajax_obj._dm_xmlhttprequestobject.responseText, g_ajax_obj._dm_param, g_ajax_obj._dm_param2 );
if( typeof g_ajax_obj != 'undefined' ) { // Just in case they nuked the object in the callback.
g_ajax_obj._dm_xmlhttprequestobject = null; // Kill the request object. we're done.
g_ajax_obj._dm_committed = false;
g_ajax_obj._dm_phase = 0;
g_ajax_obj.Dequeue();
}}}}}}}
return true;
};
if (typeof SupportsAjax == 'undefined'){ // In case we included ajax_threads.js
function SupportsAjax ( ) {
var test_obj = new c_ajax_object;
if( typeof test_obj != 'undefined' ) {
test_obj.GetNewRequestObject();
if ( test_obj._dm_xmlhttprequestobject ) {
test_obj._dm_xmlhttprequestobject = null;
test_obj = null;
return true;
}
test_obj = null;
}
return false;
};}
function SimpleAJAXCall ( in_uri, in_callback, in_method, in_param ) {
if ( (typeof in_method == 'undefined') || ((in_method != 'GET')&&(in_method != 'POST')) ) {
in_method = 'GET';
}
in_method = in_method.toUpperCase();
if ( SupportsAjax() && (typeof in_uri != 'undefined') && in_uri && (typeof in_callback == 'function') ) {
if ( in_method == 'POST' ) {
return g_ajax_obj.CallXMLHTTPObjectPOSTParam ( in_uri, in_callback, in_param );
} else { return g_ajax_obj.CallXMLHTTPObjectGETParam ( in_uri, in_callback, in_param );
} } else { return false; }};
Continua en otro post...