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

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

问题描述

我已经签署了(支付)为谷歌网站搜索。他们中有我一种Web服务,我可以将查询发送给它的URL,它会搜索我的网站,并返回的搜索结果的XML。那么我想从我的网站页面加载通过Ajax这个XML,但我不能。我可以从我的任何页面加载在我的领域,所以我假定这是因为XML是谷歌的域名。于是出现了一定是一种方法,但加载它,我不认为他们会给予我的网址,如果我不能用它做任何事情大声笑。有谁知道如何做到这一点?

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?

谢谢!

更新

这是什么页面上显示的谷歌给了我的XML:

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

如何获得XML

您可以获取XML结果您   通过更换查询+词搜索引擎   在此URL您的搜索查询:

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

<一个href="http://www.google.com/cse?cx=MY_UNIQUE_KEY&client=google-csbe&output=xml_no_dtd&q=query+terms" rel="nofollow">http://www.google.com/cse?cx=MY_UNIQUE_KEY&client=google-csbe&output=xml_no_dtd&q=query+terms

在哪里MY_UNIQUE_KEY =我唯一的密钥。

Where MY_UNIQUE_KEY = my unique key.

推荐答案

您不能加载外部文件的AJAX。但是,你可以建立自己的服务器上的文件,让你的服务器上提供的内容。例如在PHP中,你可以写一个文件 googlexml.php

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");
?>

然后你就可以访问与AJAX。我不知道,如果使用谷歌的条款将让你这样做,但如果他们这样做,那么这是一个选项。

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.

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

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