【发布时间】:2014-12-05 05:51:27
【问题描述】:
我想从没有 IFrame 或对象的 div 中的外部 url 加载页面,我需要另一种方式。谁能帮我吗。
仅当我使用 iframe 或对象时才有效。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test page</title>
<script src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
$("#siteloader").load( "https://www.w3schools.com" );
});
</script>
</head>
<body>
<div id="siteloader"></div>
</body>
</html>
【问题讨论】:
-
好吧,您已经为此使用了
.load()。只需用$(document).ready(function() { your code });换行即可 -
即使它不工作 - 摄政
-
我错过了 external 这个词。出于安全原因,您无法从其他域加载页面。
-
它是跨域请求。您需要启用 CORS。
-
由于浏览器的安全限制,大部分“Ajax”请求都遵循同源策略;请求无法从不同的域、子域、端口或协议成功检索数据。 api.jquery.com/load
标签: javascript jquery html jquery-ui jquery-plugins