简体   繁体   English

为什么这个jquery加载不起作用?

[英]Why wouldn't this jquery load work?

This is not loading the website that I wanted. 这没有加载我想要的网站。

$('#example').load("http://www.example.com");

http://www.jsfiddle.net/JFdVv/ http://www.jsfiddle.net/JFdVv/

You can't load content from a domain other than the one you're on unless it's JSONP (JSON with a function wrapper)...you can't load plain HTML like you're trying, it's blocked for security reasons by the same origin policy . 除非它是JSONP(带有函数包装器的JSON),否则您不能从所在域之外的其他域中加载内容...您无法像尝试的那样加载纯HTML,由于安全原因,该HTML已被阻止同源政策


As an aside, the reason you get an error with example_ajax_request inline in the page is that by default jsfiddle puts your JavaScript code in a wrapper...you need to have functions like that directly in the page (global functions, not scoped to a ready handler), notice the first drop down up top...it needs to be "no wrap" (either one), instead of "onDomReady" . 顺便说一句,在页面中内嵌example_ajax_request出错的原因是,默认情况下,jsfiddle将JavaScript代码放入包装器中……您需要直接在页面中具有类似的功能(全局函数,其作用域不限于准备就绪的处理程序),请注意第一个下拉列表……它必须是"no wrap" (两个都可以),而不是"onDomReady"

If you really must load a page from different website, you can always use an <iframe> although this practice would be questionable to say the least. 如果确实必须从其他网站加载页面,则可以始终使用<iframe>尽管至少可以说这种做法值得怀疑。

Or, for a server-side solution, if you're using PHP, you can have a look at the PHP cURL library . 或者,对于服务器端解决方案,如果您使用的是PHP,则可以查看PHP cURL库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM