Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 通过Ajax加载页面时加载页面时出错_Jquery_Ajax_Mobile - Fatal编程技术网

Jquery 通过Ajax加载页面时加载页面时出错

Jquery 通过Ajax加载页面时加载页面时出错,jquery,ajax,mobile,Jquery,Ajax,Mobile,我通过Ajax加载不同的页面以替换母版页中DIV(“myPage”)的内容,但每次单击页脚链接加载页面时都会出现“错误加载页面”。代码有什么问题吗 <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script> $

我通过Ajax加载不同的页面以替换母版页中DIV(“myPage”)的内容,但每次单击页脚链接加载页面时都会出现“错误加载页面”。代码有什么问题吗

 <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
 <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>
 $(document).ready(function(){
    $("#chat").click(function(){
        $('#myPage').load('./chat.html');
        $('#title').load('./constants.html #chat');
    })
    $("#address").click(function()
    {
        $('#myPage').load('./address.html');
        $('#title').load('./constants.html #address');
    })
})

</script>
    <div data-role="header" data-position="fixed" data-theme="b">
        <h1 id="title"></h1>
    </div>

    <div id="myPage" data-role="content"></div>

    <div data-role="footer" class="nav-custom" style="overflow:hidden;" id="myFooter" data-theme="b" data-position="fixed" >
        <div data-role="navbar"  class="nav-custom"  >
            <ul>
                <li><a href="function()"  id="chat" data-icon="custom">Chat</a></li>
                <li><a href="function()"  id="address" data-icon="custom">Address</a></li>
            </ul>
        </div>
    </div>

$(文档).ready(函数(){
$(“#聊天”)。单击(函数(){
$('#myPage').load('./chat.html');
$('#title').load('./constants.html#chat');
})
$(“#地址”)。单击(函数()
{
$('#myPage').load('./address.html');
$('#title').load('./constants.html#address');
})
})

控制台中的xhr响应是什么样的控制台显示了什么?-我闻到一股
HTTP 404
。你为什么要
href=“function()”
?如果您不希望anchor在任何地方引导,请将其设置为
href=“javascript:void(0)”
,或使用元素。我没有看到404错误。显示母版页后,单击导航栏上的“chat”按钮,$(“#chat”)。单击(函数()将被调用,chat.html将以$('#myPage')加载,页面实际上与“错误加载页面”显示良好同时显示消息。当人们单击导航栏中的不同按钮时,我想引导到不同的页面,因此我使用href=“function()”。我将改为输入导航栏,错误消失。谢谢你,David。