找到你要的答案

Q:Simple ajax not successful

Q:简单的Ajax不成功

I know this is probably a basic error that I have made so my apologies in advance but I did check and cannot find an answer that deals with a really basic ajax load issue like this.

I have attached all three files which I am using to test the basic functionality before making it more functional and adding it to a project I am working on. Any help would be appreciated as I cannot see why my paragraph is not updating to the message in page.html?

ajax.js contains:

$(document).ready(function(){
    $("#button").click(function(){
        $.ajax({
            url: "page.html", 
            success: function(result){
                $("#content").html(result);
            }
        });
    });
});

page.html contains:

<p>Show this</p>

ajaxTest.html contains:

<!doctype html>

<html>
    <body>
    <input type="button" value="Test Button" id="button" />

    <p id="content"></p>


    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="./ajax.js"></script>
    </body>
</html>

我知道这可能是一个基本的错误,我已经让我提前道歉,但我没有检查,无法找到一个答案,一个很基本的Ajax加载的问题这样的交易。

我已经附加了所有三个文件,我用它来测试的基本功能,使之更具功能性,并添加到一个项目,我正在努力。任何帮助将不胜感激,我不知道为什么我的段落没有更新到page.html消息?

个ajax.js包含:

$(document).ready(function(){
    $("#button").click(function(){
        $.ajax({
            url: "page.html", 
            success: function(result){
                $("#content").html(result);
            }
        });
    });
});

page.html包含:

<p>Show this</p>

ajaxtest.html包含:

<!doctype html>

<html>
    <body>
    <input type="button" value="Test Button" id="button" />

    <p id="content"></p>


    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="./ajax.js"></script>
    </body>
</html>
answer1: 回答1:

Use browser debugging tool for debugging ajax request. If you are using chrome simply press F12 and click on network tab.

And if you are using Firefox use can simply install firebug

使用浏览器调试工具调试Ajax请求。如果你使用的是Chrome只需按下F12,点击网络选项卡。

如果您使用的是Firefox的使用可以简单地安装Firebug

jquery  html  ajax