Ajax:从不同的域加载XML? [英] Ajax: Load XML from different domain?

查看:129
本文介绍了Ajax:从不同的域加载XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已申请(付费)Google网站搜寻。他们有一个网站服务的网址,我可以向它发送查询,它搜索我的网站,并返回搜索结果的XML。我试图通过Ajax从我的网站的页面加载这个XML,但我不能。我可以从我的域的任何我的页面加载,所以我假设是因为XML在谷歌的域。所以,有一个方法来加载它,虽然,我不认为他们会给我的URL,如果我不能做任何事情与它。



UPDATE

/ p>

这是在google上给我的XML的页面:


如何获取XML



您可以通过用此URL中的搜索查询替换查询+词语
来获取
搜索引擎的XML结果: / p>

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


其中MY_UNIQUE_KEY =我的唯一键。

解决方案

您无法使用AJAX加载外部文件。但是,您可以在自己的服务器上设置一个文件,使服务器上的内容可用。例如在PHP中,您可以写一个文件 googlexml.php

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

然后你可以使用AJAX访问它。我不确定Google的使用条款是否会允许您这么做,但如果他们这样做,那么这是一个选项。


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.

解决方案

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.

这篇关于Ajax:从不同的域加载XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆