-2

So. I have below Jquery/Ajax and .hide() method doesn't seems to hide the element loadingdiv.

<script type="text/javascript">
        $(document).ready(function ($) {
            //show a progress modal of your choosing
            $('#loadingdiv').show();

        $.ajax({
            url: "@Url.Action("ToDo","Test")",
            dataType: 'html',
            success: function(data) {
                $('#bookListDiv').html(data);
            }});
        });
        $('#loadingdiv').hide();
</script>
2

2 Answers 2

1

Assuming you have some HTML like this:

<div id="StaticContent">
  ...
</div>
<div id="DynamicContent">
  <img src="~/Content/Images/ajax-loader.gif" alt="loading..." />
</div>

Then you can use a simple jquery load() call to achieve what you want.

$(function() {
  $('#DynamicContent').load("/path/to/api");
});
Sign up to request clarification or add additional context in comments.

Comments

-1

I think the hide() function appears not to be working because it is not being called when you think it is. The way you have written the script tag, the hide() function is called before the page ready function. Change your markup to call the hide() function inside the ajax success callback.

$.ajax({
        url: "@Url.Action("ToDo","Test")",
        dataType: 'html',
        success: function(data) {
            $('#bookListDiv').html(data);
            $('#loadingdiv').hide();
        }});

However, if you follow the advice in the other answer, this step is unnecessary. The loading gif will be replaced by the contents returned to the ajax call.

Comments

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.