// Ajax comes to the rescue | Light At The End Of The Tunnel Ajax comes to the rescue – Light At The End Of The Tunnel

Light At The End Of The Tunnel

systems administration meanderings

Ajax comes to the rescue

I help out with the kids school web site. They wished to update some of their content by themselves. This particular content comprised a PDF file and a link to it. Using the existing pages would mean they created a PDF file, find the location in the HTML where to add a new entry, and then add the HTML code to add the new PDF file to the content and then upload the new file and the new content.

The issue here is that the code to the page is confusing to the novice, and as I don’t use an editor that they have on their DET produced desktops, how do I get them to produce their own content?

This is easy I hear you cry, just use ASP or PHP to read a file and create the content from the entries in the file! Only problem with this is that the DET do not allow active content on their web servers.

Fortunately for me, I found the solution was to use Ajax. In this way I could get the school to update a very simple XML file with the title of the PDF and the location of the PDF file. Therefore, the XML entries look like this:- [xml]

<title>A new file title</title>

<url>/pdf/a-new-file-title.pdf</url>

Now the template of the page has the javascript code added to read the XML file. A entry is added to the main section of the HTML and the javascript populates the entries appropriately, creating the links to the actual PDF files. A bit of CSS then recognises that there are links to PDF files and adds an icon, that is a link, to Adobe Reader if the reader requires to download it.

So now all the school has to do is add an entry to the XML file. Then upload the new XML file and the new PDF file. The javascript code only checks every hour that the file is updated, so within an hour the entry appears. Job done!

I’ll add a link to the this page when it goes live.


Share

#