问题描述
我怎样才能使用jquery获得外部URL的HTML?
简短的回答是你不能,因为AJAX请求通过限于相同(子)域和端口。相同的限制适用于 通常的方法是使用服务器端脚本(例如用PHP编写)作为代理:它获取外部网站的内容并将其返回给JavaScript 。它必须在与页面相同的域上运行。 显然,使用此解决方案时,可以对URL,图像,样式表等进行相对引用(例如 How can i get external URL's HTML using jquery? The short answer is you can't, because AJAX requests are limited to the same (sub)domain and port by the Same Origin Policy. The same restrictions apply to The usual way is to use a server-side script (written e.g. in PHP) that serves as a proxy: It fetches the external site's content and serves it back to JavaScript. It will have to run on the same domain as the page. Obviously, using this solution, relative references to URLs, images, stylesheets and such (e.g. 这篇关于在jquery中获取外部网址的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! iframe
元素:您不能创建 iframe $ c $指向外部页面,并从那里获取它的HTML。
../ images / image.gif
)将不再起作用,因为它们不在页面上下文中。无论如何,这在你的情况是一个问题是不可能的。一种解决方法可能是使用。 iframe
elements: You can't create an iframe
pointing to the external page, and grab its HTML from there. ../images/image.gif
) will no longer work, as they areout of context on your page. Whether that is a problem in your situation is impossible to tell. One workaround for that may be using a <base>
tag.