Ajax before / after and error events

Are there beforeSend(), afterSend() and error() global functions similar to jQuery ajax()?

see docs.jquery.com/Ajax_Events

I’d like to have a global error handler instead of writing it for each page.

There are not such events. Please see docs and example of usage:

dhtmlxAjax/samples/01_samples_of_usage/01_send_request.html

I created wrapper functions which to call my own event functions, working perfectly. By writing my own, I am able to add a global event handler to preprocess the result, parse for errors then dhtmlx message the error.

It’s actually nicer than jQuery’s ajax event functions because the preprocess event handler is missing in jQuery’s library.

app.post_beforeSend=function(){		//the global before send event function 
	//do things here
}	

app.post_resultPreprocess=function(result){		//the global preprocess result function ... my global error handeler
	if (!result.success)   {
		dhtmlx.alert({ title:"Problem", type:"alert-error", text: result.msg});
		return false;
	}
	return true;
}	

app.post=function(callback, debug) {
	if (debug == undefined) debug=false;

	app.post_beforeSend();
	if (debug) alert(GurlBase + " " + GurlParam);
	
	dhtmlxAjax.post(GurlBase,GurlParam, function(loader) {
		if (debug) alert(loader.xmlDoc.responseText);			
		
		var result = JSON.parse(loader.xmlDoc.responseText)
		if (app.post_resultPreprocess(result)) 
			callback(loader, result.msg);
	});
}

*I’m using app namespace so the global namespace can be preserved

Then to ajaxPost: (note: I have functions to set my post data: GurlBase & GurlParam)

    app.post( function(loader, msg) { app.msg("Note has been saved.") });

I’ve also made a form send() serialization type of function which winds up calling app.post().

The main reason I wanted app.post is to so that I can have a global error handler. Also in app.post_beforeSend() I need to do a few application specific things.

Hi,

thank you for sharing your solution.