Verify that the contents of the div loaded

2

Is it possible to know if the content within div loaded with jquery ? Same as body .

I want to make a visual effect of the type where a loading image appears and only after the post inside the div loads completely will it be displayed.

I searched google but did not think anything about it. There is no way?

    
asked by anonymous 15.01.2017 / 06:45

1 answer

1

Hello, usually when you make calls like load comments, this is done with ajax , so that the page is not reloaded when doing the request.

Using ajax, you can put a div with a loading when you make the request [of comments] and withdraw it when you finish and popular the div with the comments.

Follow the example below:

HTML

<div id="comentarios"><img scr="loading.gif" /><\div>

JS

 $.ajax({
  url: "loadComentarios.php",
  context: document.body
}).done(function(data) {
  $('#comentarios').html(data);
});

Notice that there is a done option in ajax. This is called when the request ends, and has as parameter what was returned from your php (in this case, the comments). You remove the loading and replace it with the comment list.

    
10.03.2017 / 20:22