1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| /**
* internal callback function.
*
* will perform some consistency checks (response code, NULL value testing)
* and if response_type = 'OBJECT' it will automatically call
* cpaint_call.parse_ajax_xml() to have a JavaScript object structure generated.
*
* after all that is done the client side callback function will be called
* with the generated response as single value.
*
* @access protected
* @return void
*/
var callback = function() {
var response = null;
if (httpobj.readyState == 4
&& httpobj.status == 200) {
debug(httpobj.responseText, 1);
debug('using response type ' + config['response_type'], 2);
// fetch correct response
switch (config['response_type']) {
case 'XML':
debug(httpobj.responseXML, 2);
response = __cpaint_transformer.xml_conversion(httpobj.responseXML);
break;
case 'OBJECT':
response = __cpaint_transformer.object_conversion(httpobj.responseXML);
break;
case 'TEXT':
response = __cpaint_transformer.text_conversion(httpobj.responseText);
break;
case 'E4X':
response = __cpaint_transformer.e4x_conversion(httpobj.responseText);
break;
case 'JSON':
response = __cpaint_transformer.json_conversion(httpobj.responseText);
break;
default:
debug('invalid response type \'' + response_type + '\'', 0);
}
// call client side callback
if (response != null
&& typeof client_callback == 'function') {
client_callback(response, httpobj.responseText);
}
// remove ourselves from the stack
remove_from_stack();
} else if (httpobj.readyState == 4
&& httpobj.status == 401) {
// HTTP 401 error
debug('HTTP authorization required or credentials were invalid', 0);
} else if (httpobj.readyState == 4
&& httpobj.status != 200) {
// HTTP error of some kind
debug('invalid HTTP response code \'' + Number(httpobj.status) + '\'', 0);
}
}
/**
* removes an entry from the stack
*
* @access protected
* @return void
*/
var remove_from_stack = function() {
// remove only if everything is okay and we're not configured as persistent connection
if (typeof stack_id == 'number'
&& __cpaint_stack[stack_id]
&& config['persistent_connection'] == false) {
__cpaint_stack[stack_id] = null;
}
} |
Partager