Ajax: Load XML from different domain?

后端 未结 3 1499
天命终不由人
天命终不由人 2020-12-21 15:10

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 sea

相关标签:
3条回答
  • 2020-12-21 15:30

    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.

    0 讨论(0)
  • 2020-12-21 15:37

    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...

    0 讨论(0)
  • 2020-12-21 15:56

    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"

    0 讨论(0)
提交回复
热议问题