

/**
 * EAX-Handler for Ajax-Requests and Result-Processing with jQuery
 *
 * @author		JA
 * @copyright	Copyright e-matters GmbH; 2010, www.e-matters.de
 * @since		16.03.2010
 * @version		1.0.0
 *
 * @param		String url, must.  Ajax-URL with Action-Commands
 */

function eax_ajax_read(url)
{
	// send ajax request to the server
	$.ajax({
		// request url
  		url: url,

  		// request type
  		type: "GET",

  		// type of the result data
  		dataType: "json",
  		
  		// run requests synchronous 
  		async: false,

  		// cache directive (no caching)
  		cache: false,

  		// timeout for request (milliseconds)
  		timeout: 10000,


  		//--- success callback function
  		success: function(data, status, req) {

					// check if data from server returned
					if (data) {

						// loop over result entries
						for (i=0; i<data.length; i++) {
							// check status from result entry
							if (data[i].status==true){

								// action switch
								switch (data[i].action){

									//-- html_set action
									case 'html_set':
										// set html sourcecode in tartget div
										$("#"+data[i].trg_id).html(data[i].src);
										break;


									//-- cb_func_call action
									case 'cb_func_call':
										// convert array to json string
										var jsonStr =$.toJSON(data[i]);
													                    
										// eval callback function
										var cb_fnc = data[i].cb_fnc + "(" + $.quoteString(jsonStr) + ");";
										jQuery.globalEval(cb_fnc);
										break;


									//-- none action
									case 'none':
										// do nothing, is all fine
										break;


									//-- unknown action
									default:
										// result action is not defined
										 break;
								}

							} else {
								// status is false, action failed
							}
						}

					} else {
						// response data empty
					}
  				 } ,


  		//--- error callback function
  		error: 	function(req, status, error) {
					// action failed
  				}

	});
}







