1

jQuery はまだ初めてなので、次の点で助けが必要です。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery demo</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
     $(document).ready(function() {
         $('.nav-link').click( function() {
            var href = $(this).attr('href');
            $('#content').load( href, function() {
                alert("Yeahhhh !");
            });
            return false; // don't actually follow the link
         });
     });
</script>

<div class="menu">
    <ul>
    <li><a href="http://www.google.com.my/" class="nav-link"> Yeah 1 </a></li>
    <li><a href="C:\Testing\Yeah1.html" class="nav-link"> Yeah 2 </a></li>
    </ul>
</div>


<div id="content">
    ... Initial Content...
</div>  
 </body>
 </html>

私は testing.html と呼ばれるこの HTML ファイルを作成し、テスト用に Yee1.html と呼ばれる別の単純な HTML ファイルを用意しました。jQuery コードを配置する前に、リンクを Yee1.html に向けることができます。

ただし、jQuery コードを配置した後$('#content').load( href);、その DIV にコンテンツをロードできるはずであり、「Yeahhhh !」というメッセージ アラートも表示されます...しかし、それでもコンテンツはロードされません。

4

4 に答える 4

1

あなたのドメインに存在するものは何でも読み込むことができますが、セキュリティ上の理由から、他のドメインからページを読み込むことはできません。

http://api.jquery.com/load/ 追記事項: ブラウザのセキュリティ制限により、ほとんどの「Ajax」リクエストは同一オリジン ポリシーの対象となります。要求は、別のドメイン、サブドメイン、またはプロトコルからデータを正常に取得できません。

于 2011-08-24T15:49:40.063 に答える