BlogGalleryContact

anatomy of an ajax request

What is happening ona Ajax request and how we have to react on that what happens:

Pre Request
Previous to the request we need to instanciate the ajax framework and load all classes.

Firing the request
We need to tell the gui NOT to handle additional clicks for specific parts of the gui, since it could be possible taht a dom id is missing that is needed by the later dom wirte stuff that happens when you server has performed the action and returned a result. Since you can not be sure that the gui is in the same state and you can not make a

var result = myajaxfunc();

just because of the asyncronous nature of the whole thing. There is need for the information what part of teh gui should be blocked, aka event-cancelled

Working with the results data
OK its starting to get a bit tricky, now were in the real events of that ajax request. Since we are doing Async (the A in Ajax) data retrieval, its not possible to do (cant stress this enough)

var result = myajaxfunc();

So you have to use the abillity of javascript to tell it which function name it should use, or which anonymous function i pass. So (simple) the above example gets

var func_result = function (return) {
// domesomething withmyresult
}

myajaxfunc(func_result);

Oops a error occured
Various errors can happen:

- postnuke function does return errormsg
- request status is not 200
- malformed data
- unknown postnuke function called

The first 3 need to be handeled, for the fourth pnAjax will have a re-written pnmodapifunc method, that will NOT return a error page when you call a unknown function (are we java or what ?, who did this .. i dont get it till today, i guess ill need to get my german sheppards on this guy ... wot kind of system design is tis ?) .... anyway .. in a stack of 10 funcs all these errors can occur and need to be handeled ....

Finalizing the thing
If you called 10 Postnuke functions you might need som post processing, that takes polace in the on finalize handler ;) You can gather the results here (like for example getting the products of categorie dogs and birds), match the together and stick them into the pn datagrid ;)

Related Entries:
sebs 1 eval in jsObjects 0
pnajax with json further developments
everthing new
foxy web developer toolbox
talk at xtech
 Permalink

Comments

No new comments allowed (anymore) on this post.