Do .append () before .load ()

2

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

For this I tried to .append before .load :

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

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

How do I get around this?

    
asked by anonymous 06.05.2014 / 12:40

1 answer

2

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

$.get('/ContratoCli/carregaProduto', {serie: $("#Serie").val(), numDoc: $("#NumDoc").val()}, function(data) {   
    $('#Produto').append($('<br />')).append(data);
});
    
06.05.2014 / 13:28