1

我确信这很简单,但我试图让一个简单的 jquery ajax 调用工作。我有两个文件,index.html 和 page.html,它们都在同一个目录中。

这是 index.html 的内容:

<!DOCTYPE html>
<html>
<head>
    <title>Simple Ajax call</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
</head>
<body>
    <h1>ajax call</h1>
    <p><a href="#">Click here to fetch HTML content</a></p>
    <div id="result">

    </div>

    <script type="text/javascript">

        $(document).ready(function(){
            $('a').click(function(){
                $('#result').load('page.html');
            });
        });

    </script>

</body>
</html>

这是 page.html 的内容:

<strong>Loaded</strong>

我很困惑为什么这不起作用,当我单击链接时没有任何反应。

4

1 回答 1

0

尝试这个:

<script type="text/javascript">

        $(document).ready(function(){
            $('a').click(function(){
                $.get("page.html",function(result){
                   $('#result').html(result);
                });
                return false;
            });
        });

    </script>
于 2013-10-02T21:24:55.867 回答