How to perform a reload on only one part of the page, from an ID?

0

I'm trying to do a reload just for content from within a div.

<div class="panel-body">                          
   <pre>
     <p  id="content" th:utext="${log.content}">Log content</p>
  </pre>
 </div>

I was able to make the whole page update itself:

$(document).ready(function() { setInterval("location.reload(true)", 10000); });

But applying the same logic to an ID did not work very well:

$(document).ready(function() { setInterval("$('#content').reload(true)", 10000); });  

My question: How do I make a realod only on the contents of this <div></div> , from an ID?

    
asked by anonymous 18.07.2018 / 17:36

1 answer

0

You can use Ajax to run a given function from a URL and update the contents of your div with the function return. That way you will not be reloading your entire page. An example of ajax would be:

var formdata = new FormData($("#myform"));
$.ajax({
    url: "exemplo.php",
    type: "POST",
    data: formdata,
    success:function(data){
        $("#div-id").html(data);
    },
    error: function(){
        $("#div-id").html("Mensagem de Erro");
    }
});

You'll find more details at this link: link

    
18.07.2018 / 17:50