The fact is that just adding ajaxlib.php only loads a small set of functions that allows setting up ajax gently. (such as loading require_js() ). It does not include anything about YUI within the page. All client ajax code should be added from here, once you ensured all the necessary YUI js libs are in the place.
The way synchronizing data base with a change performed client side is to use a YAHOO.Util.Connect object. Here is a piece of code that implements that kind of query :
<script type="text/javascript">
// this is an array capable of providing adequate handlers
// to some response code from the server. sectionSpan gets
// an element reference the handlers does somethin with.
var ajaxSectionLoaderResponse = {
success: function(o) {
sectionSpan = document.getElementById('sections');
sectionSpan.innerHTML = o.responseText;
},
failure: function(o) {
sectionSpan = document.getElementById('sections');
sectionSpan.innerHTML = '<?php print_string('nosectionsfailure', 'coursexfers') ?>';
}
}
// I call the asynchronous request on a "onChange" situation
// in this example, though this function :
function ajaxSectionUpdater(choiceobj){
sectionSpan = document.getElementById('sections');
if (choiceobj.selectedIndex != 0){
// allows me to display a waiting gif in the meanwhile :
sectionSpan.innerHTML = '<img src="<?php echo $CFG->pixpath.'/i/ajaxloader.gif' ?>" />';
// calling the ajax asynchronous server side handler :
var sUrl = '<?php echo $CFG->wwwroot.'/course/ajaxsectionloader.php?course='; ?>' + choiceobj.options[choiceobj.selectedIndex].value;
// performing the query, the event handlers will be triggered in a while :
var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, ajaxSectionLoaderResponse, null);
}
else{
sectionSpan.innerHTML = '<?php print_string('coursechoicerequired','coursexfers') ?>';
}
}
</script>
Now can just the server side handler, basing its work on sufficiant parameters, perform all the database changes we expect.
Note that YUI Connect object also allows you to perform POST queries, where the amount of send data can be higher than using GET.