开发者

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/


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.


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".


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.

Or, for a server-side solution, if you're using PHP, you can have a look at the PHP cURL library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜