There is no duplicate of this : How to execute a jquery script when loading a page
I have a function that lists a content in a div
:
function listar() {
alert("listar"); // alert para saber se está sendo chamado
arquivo = "lista.php";
$.ajax({
url:arquivo,
success: function (textStatus) {
$('#iddiv1').html(textStatus);
}
});
}
I tried to load this function next to the page, but it does not work:
$(document).ready(function(){
listar();
});
Also, I would like while running method listar()
, to hide div
.
Example:
$('#iddiv1').hide();
$('#iddiv2').show();
I tried this way, but without success:
$('#iddiv1').load(function() {
$('#iddiv1').hide();
$('#iddiv2').show();
});