1

以下是我的完整代码。我一定是在做蠢事。我以前用过这个......它不应该是单源策略,因为我实际上是从服务器运行它,而不是在本地运行它。我得到零控制台错误。如果我在 load 语句上放一个断点,它确实会命中它。

http://mysite.com/reports/PendingFulfillment.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>All Requests Pending Fulfillment</title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script src="Scripts/jquery-ui-1.9.0.min.js"></script>
    <link href="Content/normalize.css" rel="stylesheet" />
    <link href="site.css" rel="stylesheet" />
    <script src="Scripts/scripts.js"></script>
    <script type="text/javascript">
        //$("#Content").load("http://mysite.com/somelongdynamicwpfurlIreallywanttoload #documentBody");
        $("#Content").load("http://mysite.com/reports/index.html"); // <-- simplified for testing
    </script>
</head>
<body>
    <h1>All Requests Pending Fulfillment</h1>
    <div id="Content"></div>
</body>
</html>
4

2 回答 2

2

That's because when you select the element, that element is not added to the DOM yet, you should put your code within document ready handler:

$(document).ready(function() {
    $("#Content").load("http://mysite.com/reports/index.html"); 
})
于 2012-11-05T19:47:00.543 回答
1

Your code needs to either be moved to the end of the document or placed within a document.ready call. You're attempting to execute the code before the page and #Content element has been loaded.

E.g.

$(document).ready(function() {
    $("#Content").load("http://mysite.com/reports/index.html"); // <-- simplified for testing
});
于 2012-11-05T19:47:09.490 回答