Private Social Media
Try out 'Friends and Family' - FnF, an alternative system for use by private groups.
Simple installation designed to work with shared hostings.
No advertising, no annoying notifications.
Getting Started with Datatables - Populating via AJAX.
If you're reading this then you are presumably already including jquery.js in your pages, so you might also be interested to read my notes on Getting Started with jQuery Plugins.
Introduction.Having started on this Datatables tack I thought I'd add something else that I wanted to do, got working quite quickly, but never quite understood until I made myself write this. It might be useful to others. The topic here is population of the table from an external source via AJAX. There are some philosophical points in this process, which I'll summarize as "MIME types required."
Nitty Gritty.The first thing we need to do is to modify the initialization of the table to tell it how to get the data. We'll start with a plain old text file.
The contents of this file can be:
This is what 'sAjaxSource' expects - an array of arrays of data, where the inner arrays contain the data for each row. Then we need to strip out the existing table contents so we're left with just:
When we've done that we have dt107.html, the result of which can be seen here. We should get exactly the same result if we change our initialization to:
where the PHP file is:
This is so, and the implication is that when the web server serves up a text file it labels it as "Content-type: text/plain". However, if we change the PHP file so that it says:
Note that I've added another global variable - oTable - to hold a reference to the table object for use during the refresh. Don't forget to add that to the initialization code:
We'll also have to add something to dt107.html to provoke a refresh, like:
Actually, to make that look sensible, you have to do a little more, but you can see what that is in the HTML for dt108. So we're down to "Get the aaData object from the JSON response." How we do that depends on the MIME type in our PHP file. If we use 'text/plain' then what we need is:
Otherwise - MIME type 'application/json' we must use:
Check out the completed dt108.