Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Safari and XMLHttpRequest

May 22

I was working on finishing version 1.1 of my Golf Tips widget and ran into a little problem. I’ve been adding the functionality to click on the golf ball to get a new tip. The problem was that the requests appeared to be cached and each request after the first would return an error. The initial code looked like this:

function getData()
{
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open(“GET”, “http://www.db75.com”, true);
req.send(null);
}

After searching around for answers I stumbled across the setRequestHeader attribute. With this attribute we can essentially set an expiration date that will essentially tell the request object to always make the request. The modified code looks like:

function getData()
{
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open(“GET”, “http://www.db75.com”, true);
req.setRequestHeader(‘If-Modified-Since’, ‘Wed, 18 May 2005 00:00:00 GMT’);
req.send(null);
}

This means that version 1.1 of Golf Tips should be available later today! Just doing some final testing and I’ll post when it’s ready.