Monday, September 14, 2009

Skype status (xml file), jQuery and Apache MIME

Well, maybe it was not so scary, but it took me a couple of minutes to solve it.
Skype provides information about user status on-line, for example:
http://mystatus.skype.com/telewizyjna.xml
It's ok, but status file is outside my domain, so browsers (unless you hack them to omit security rules) 'll refuse to process AJAX request.
Solution? Simple php file getting content of external xml just to display it locally.
Straight forward, isn't it? But then came famous MIME type problem, and jQuery couldn't parse my php file, because MIME was sent to browser as text/html, not as text/xml.
Finally what I did:
status.get file, to get xml file content and display it on local server as an xml
(in .htaccess directive AddHandler php5-script .get)
status.get code with header set to text/xml

header ("Content-type: text/xml");
$status = file('http://mystatus.skype.com/telewizyjna.xml');
foreach($status as $display) {
print($display);
}


And that's all. The most important - it works. (tested with Ubuntu Jaunty plus XAMPP and Firefox 3+ and Opera as browsers)

Remark: do not put anything like AddType "text/xml" .get to your .htaccess file. PHP header is enough to determine content type.

No comments:

Post a Comment