JavaScript AJAX – Load XML from Different Domain

ajaxcross-domainjavascript

I have signed up(paid) for Google site search. They have me a url of a sort of web service where I can send a query to it, it searches my site, and it returns XML of the search results. Well I am trying to load this XML via Ajax from a page on my site but I cannot. I can load from any of my pages on my domain so I am assuming it is because of the XML being on Google's domain. So there has got to be a way to load it though, I don't think they would have given me the URL if I couldn't do anything with it lol. Does anyone know how to do this?

Thanks!

UPDATE:

this is what the page says on google that gave me the XML:

How to get XML

You can get XML results for your
search engine by replacing query+terms
with your search query in this URL:

http://www.google.com/cse?cx=MY_UNIQUE_KEY&client=google-csbe&output=xml_no_dtd&q=query+terms

Where MY_UNIQUE_KEY = my unique key.

Best Answer

You can't load external files with AJAX. However, you can set up a file on your own server that makes the content available on your server. For instance in PHP, you could write a file googlexml.php:

<?php
@readfile("http://www.google.com/cse?cx=MY_UNIQUE_KEY&client=googlecsbe&output=xml_no_dtd&q=query+terms");
?>

And then you could access that with AJAX. I'm not sure if Google's terms of use will let you do that, but if they do, then this is an option.

Related Question