How to update specific div using JQuery AJAX after regular time intervals?

595 Views Asked by At

I want to update specific div - not full html page .When i run the following code it works fine but it reloads whole html. Moreover, I'm using different layouts e.g i have header, layout, footer in different file.

$(document).ready(function() {
  setTimeout( function(){  
    $.ajax({
      url: 'http://localhost:3002/jrt/?jId=$data.jacket.id',
      method: "GET",
      cache: false,
      success: function(data) {
        //$("#gt").append(data);
        $( '#gt' ).html( data );
      },
      error: function(jqXHR, textStatus, errorThrown) {
        alert('error ' + textStatus + " " + errorThrown);
      }
    })
  },10000);
})
1

There are 1 best solutions below

3
On

assuming the data returned is html you can select something in it by doing $(data).find('your-selector') to edit your example:

[...]
success: function(data) {
   $( '#gt .something-inside' ).html( $(data).find('.something-inside') );
},
[...]