upload content after an element

2

I'm trying to make a function to load a content with .load() of jQuery , .load() receives a parameter param that would be the address of the file. And I would like this html to be loaded after a specific element, in the aside case. I tried using the .after() method but I could not, I wonder if anyone has a solution?!

And I have another question, after loading this new content, if the methods that are within $(document).ready(); will still work, to interact with the new loaded elements?!

HTML line where onclick event is

<li class="list-group-item pointer" onclick="getTemplate('admin/email/lista-emails.php')">
  Lista de E-mails
  <span class="indicador success white right">14</span>
</li>

Javascript Code

function getTemplate(string){
  $("#here").after().load(string);
}

Note: He uploaded the content inside aside

    
asked by anonymous 21.02.2017 / 03:45

3 answers

0

I was able to resolve it as follows:

function getTemplate(string){
  $.ajax({
    type     : 'GET',
    url      : string,
    dataType : 'html',
    success  : function(data){
      //remove o conteudo caso já tenha carregado
      //e evita carregar multiplas vezes o mesmo conteudo
      $("#loadContent").remove(); 
      //carrega o html após o elemento ASIDE que resultou na consulta.
      $('aside').after(data);
    }
  });
}
    
22.02.2017 / 03:05
2

You can use $ .get () to fetch content and insertAfter () to position it, instead of load () and after ();

function getTemplate(string){
  var html = $.get( string );
  $( html ).insertAfter('#here');
}
    
21.02.2017 / 04:40
0

Could be done using done from $ .getJSON ();

So:

funtion getTemplate(parametro){
  $.getJSON("url", data : {paramentronome : paramento }).
   .done(function (dado ) {
      $("#div").html(dado);
   });
}

Does this help?

    
21.02.2017 / 15:28