2

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-->
1
  • Does the firebug/javascript console show anything? Commented Dec 19, 2011 at 7:16

2 Answers 2

6

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();
    ....
Sign up to request clarification or add additional context in comments.

Comments

1

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
  });
});

4 Comments

Returning false should be avoided.
Was not aware of that. Thanks for the heads up. Any idea if jQuery provides a compatibility layer for IE6/7 that don't support this?
Follow this answer, for IE you should use event.returnValue = false.
I checked the latest source and it seems to provide it. Not sure when they added it though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.