Pregnancy Timeline

Friday, April 8, 2011

Ajax and Google Sites

My main project in Wizard Clocks has been to create an easy way for somebody to embed a clock into their own web pages. My first idea was to use AJAX to load an XML file from the website, but that ran into trouble. I kept getting an HTTP 302 status, saying that the file was "temporarily relocated", and no data.

Eventually, I figured out that sites.google.com sends an HTTP 302 for all of the files it serves; your web browser sees the message and retrieves the document from the new location (which it can get from the Location header from HTTP response). Ordinarily, you wouldn't see this status, but the address that you are redirected to has a different domain name, so the same origin AJAX restriction prevents you from getting the content. Brick wall.

Attempt number two was to try creating an iframe with the URL of the data file. This failed when I was refused permission to examine the iframe's contents.

Finally, it occurred to me that there is another way to store the information I needed: Javascript! All you have to do is to code the data into a Javascript variable, then your application could create a SCRIPT tag in the HEAD of the document, and the browser will load it like any other script. I am rolling again.

WC

No comments:

Post a Comment