Make . append() before . load()

Asked

Viewed 104 times

2

I’m using the .load() to load content (partial) from controller of my application. What I wanted to do before the .load, was to add code html while carrying a partial.

I tried to do it .append before the .load:

$("#Produto").append($('<br />')).load('/ContratoCli/carregaProduto', { serie: $("#Serie").val(), numDoc: $("#NumDoc").val() });

What’s happening is that the load uses the div all and I can’t add the <br /> before (delete and load over), getting:

inserir a descrição da imagem aqui

How do I get around this?

  • And if you use a prepend (http://api.jquery.com/prepend/) after load?

1 answer

2


The problem is that the .load() will always replace the element content. What you can do is use the method .get() and within it the .append(), see:

$.get('/ContratoCli/carregaProduto', {serie: $("#Serie").val(), numDoc: $("#NumDoc").val()}, function(data) {   
    $('#Produto').append($('<br />')).append(data);
});
  • That was exactly the problem, and this is the solution! Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.