-1

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);
})
Sooraj Abbasi
  • 110
  • 16
DEO
  • 316
  • 2
  • 4
  • 18
  • Possible duplicate of http://stackoverflow.com/questions/25446628/ajax-jquery-refresh-div-every-5-seconds. Search before asking questions – Garfield Dec 26 '16 at 13:36
  • You're updating a specific element: `$('#gt').html(data);` If you want to update a different element, change the selector to identify that element instead. – David Dec 26 '16 at 13:37
  • Show us your HTML too.. is `html` has the id `gt`? If not, who the element `#gt`? – Mosh Feu Dec 26 '16 at 13:41
  • yes its like
    – DEO Dec 26 '16 at 13:43
  • But this section is the root element? I mean, is he wrap the whole page or part of it? If it's wrap only, part it shouldn't refresh the whole page. Maybe it something else. – Mosh Feu Dec 26 '16 at 13:45
  • Also, why are you including the domain (e.g. localhost) in the url? You know that when you will publish it, you will have to change this? It will be better if you call the relative path (without the domain) – Mosh Feu Dec 26 '16 at 13:47
  • am using markojs which uses templates . and am including files like – DEO Dec 26 '16 at 13:48
  • am using markojs which uses templates . and am including files like
    – DEO Dec 26 '16 at 13:50
  • So `#gt` is the app wrapper. If you want to change more specific section, try to change the selector.. – Mosh Feu Dec 26 '16 at 13:53

1 Answers1

1

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') );
},
[...]
  • `assuming the date returned is html` - why are you assuming this? Read the comments.. – Mosh Feu Dec 26 '16 at 13:48
  • @moshFeu because you said the whole HTML reloads, so i assumed it reloads with other HTML you get form the request. anyway then you just have to do `$( '#gt .something-inside' ).html( data );` – Karim Cossutti Dec 26 '16 at 13:51
  • Apparently you are kind of right. Is not the `html` element but it's the root element of the application.. – Mosh Feu Dec 26 '16 at 14:00