views:

1297

answers:

3

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.

+1  A: 

Does google not offer the ability to forward a DNS address to the IP of your service, folding it into your domain? This way you can do in AJAX

googleAlias.mydomain.com

Google should support this, but I don't know for sure. I imagine they would in the same way they do with GMail and external-domain mail.

Removes your cross-domain javascript issues

edit I expanded below and another user helpfully pointed out this should work (thanks Stobor)

Well, to get my company mail into GMail, if I recall, I needed to change the MX record on my DNS to point to a google IP. You may be able, if google supports it, to add an A record to your domain so an AJAX request to foo.yourdomain.com is the same as search.google.com or whatever. Google needs to recognize requests from your hostname in the A record and say "Oh yes, that's me, on my client's behalf"

Aiden Bell
I don't know, to tell you the truth what you said is over my head.
John Isaacks
Well, to get my company mail into GMail, if I recall, I needed to change the MX record on my DNS to point to a google IP. You may be able, if google supports it, to add an A record to your domain so an AJAX request to foo.yourdomain.com is the same as search.google.com or whatever. Google needs to recognize requests from your hostname in the A record and say "Oh yes, that's me, on my client's behalf"
Aiden Bell
I could be barking up the wrong tree here though.
Aiden Bell
@Aiden: Just did a quick test by manipulating my hosts file, this does seem to work.
Stobor
@Stobor, Nice :)
Aiden Bell
+2  A: 

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&amp;client=googlecsbe&amp;output=xml_no_dtd&amp;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.

Rudd Zwolinski
Good suggestion. Do note that this only works if fopen wrappers are enabled in php, which isn't always the case due to security implications... http://au.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Stobor
I actually had this idea last night, I was thinking cURL though, I tried your suggestion and it is just returning a blank page.
John Isaacks
A: 

For those coming across this now, the AJAX Search API may be what you want: http://code.google.com/apis/ajaxsearch/documentation/

EDIT: Actually, upon further review, that may not hook in with the site search...

James Frank