Click to See Complete Forum and Search --> : PHP How do I serve an XML file as a web service in PHP?


fredramsey
June 9th, 2011, 08:10 AM
I would like to have a web service in PHP simply send an existing XML file - this is to get around the cross-site XMLHttpRequest limitation. I need to read it in JavaScript on the client end.

Can this be done?

I am a PHP n00b, so any code example some kind soul can provide would be greatly appreciated.

:-)

PeejAvery
June 9th, 2011, 11:14 AM
All you need is to set your header for XML content and then output pure XML.

<?php
header ("Content-Type: text/xml");

echo $xmlContent;
?>

fredramsey
June 9th, 2011, 11:24 AM
That's cool, but I think you're still limited by JavaScript's inability to read a file located on another server. I was really looking to make it into a Web Service I can call.

Thanks, though, I did learn something.

PeejAvery
June 9th, 2011, 11:46 AM
You misunderstand JavaScript's cross-domain policy. JavaScript can read files on other domains...it cannot interact with DOM elements on other domains.