简体   繁体   English

jQuery .load()函数不返回任何内容

[英]jQuery .load() function returning nothing

I have the following block of code in Index.aspx . 我在Index.aspx有以下代码块。 When I click on button the page, it reloads and shows nothing (empty page). 当我单击该页面按钮时,它会重新加载并且什么都没有显示(空白页面)。

<div class="filter_block">
                <span>Show</span>
                <a href="#"><span class="title">full shedulle</span></a>
                <a id="buttonFindFilmByName" class="active"><span class="title">films name</span></a>
                <script type="text/javascript">
                    $(document).ready(function () {
                        $("#buttonFindFilmByName").click(function() {
                            $('#listInfoBlock').load('cinema/filmlist');
                        });
                    })
                </script>
            </div><!-- .filter_block-->

            <div id="listInfoBlock" class="list_infoBlock">           

            </div><!-- .list_infoBlock-->

Your page is reloading because that's the standard browser 's behavior when the user clicks on a a (link) HTML element. 您的页面重新加载,因为这是标准的浏览器的行为,当用户点击一个上a (链接)HTML元素。

You can stop this default behavior by using a parameter in the click handle and calling the preventDefault method : 您可以通过在单击句柄中使用参数并调用preventDefault方法来停止此默认行为:

$("#buttonFindFilmByName").click(function(e) {
    e.preventDefault();
    ....

Return false from the click handler function to tell the browser not to follow the link. click处理程序函数返回false,以告诉浏览器不要遵循该链接。 This also allows you to set a real link in href for browsers that don't support JavaScript, or in case the user turned it off. 这还允许您在href为不支持JavaScript的浏览器或在用户将其关闭的情况下设置真实链接。

$(document).ready(function () {
  $("#buttonFindFilmByName").click(function() {
    $('#listInfoBlock').load('cinema/filmlist');
    return false; // <====== FIX
  });
});

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

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