user348173
user348173

Reputation: 9278

jQuery .load() function returning nothing

I have the following block of code in 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-->

Upvotes: 2

Views: 313

Answers (2)

kichik
kichik

Reputation: 34704

Return false from the click handler function to tell the browser not to follow the link. 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.

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

Upvotes: 1

St&#233;phane Bebrone
St&#233;phane Bebrone

Reputation: 2763

Your page is reloading because that's the standard browser 's behavior when the user clicks on a a (link) HTML element.

You can stop this default behavior by using a parameter in the click handle and calling the preventDefault method:

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

Upvotes: 6

Related Questions