简体   繁体   English

无法获得简单的jQuery Ajax调用工作

[英]unable to get simple jquery ajax call to work

I am sure this is very simple, but I am trying to get a simple jquery ajax call to work. 我敢肯定这很简单,但是我正在尝试让一个简单的jquery ajax调用起作用。 I have two files, index.html and page.html, both in the same directory. 我在同一目录中有两个文件index.html和page.html。

This is the content of index.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>

and this is the content of page.html: 这是page.html的内容:

<strong>Loaded</strong>

I am very confused to why this does not work, when I click the link nothing occurs. 我很困惑为什么这不起作用,当我单击链接时什么也没发生。

Try this: 尝试这个:

<script type="text/javascript">

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

    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM