AJAX / jQuery的/ JavaScript的 - 访问一个页面的外部域 [英] AJAX/jQuery/Javascript - Access a page in an external domain

查看:134
本文介绍了AJAX / jQuery的/ JavaScript的 - 访问一个页面的外部域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很简单,答案可能不是。 :)

The question is quite simple, the answer may not be. :)

如何使一个AJAX请求(preferably与'jQuery的'),外部域,即网络地址(例如),从该是你要求这个页面的站点的服务器完全不同。

How to make an AJAX request (preferably with 'jQuery'), to an external domain, ie a web address (for example) completely different from the server which is the site you requested this page.

我要的是得到一个HTML页面的服务器之外,和我的网页上显示出来。

What I want is to get a html page outside of the server, and display it on my page.

我也接受来自其它方式的建议,不使用AJAX,例如,来实现这一目标。

I also accept suggestions from other way, without using AJAX, for example, to accomplish that.

感谢你,现在。

推荐答案

如果你想从该领域采取的HTML和它注入到你的页面,只是把它放在一个iframe。

If you're trying to take HTML from that domain and inject it into your page, just put it in an iframe.

如果你想获得某种形式的API,你要使用JSONP。下面是它是如何工作的好新手必看: http://devlog.info/2010 / 03/10 /跨域-AJAX /

If you're trying to access some sort of API, you'll want to use JSONP. Here's a good writeup of how it works: http://devlog.info/2010/03/10/cross-domain-ajax/

注意JSONP将需要一些修改服务器端code。如果它是专为这件事情一个受欢迎的API,它可能已经支持了。

Note that JSONP will require some changes to server side code. If it's a popular API designed for this thing, it probably already supports it.

这篇关于AJAX / jQuery的/ JavaScript的 - 访问一个页面的外部域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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