jquery - problems with the stamps of html code by javascript -
i need javascript function stamp code when put <div id="">
i tried with:
$.ajax({ url: "myurl" datatype: 'jsonp', jsonp: 'jsoncallback', timeout: 5000, success: function(data, status){ $.each(data, function(i,item){ document.getelementbyid("livello").innerhtml='<h2> '+ item.nome+' </h2>'; }); } });
but stamp last element
i tried also
$.ajax({ url: "myurl" datatype: 'jsonp', jsonp: 'jsoncallback', timeout: 5000, success: function(data, status){ $.each(data, function(i,item){ var ='<h2>'+ item.nome+' </h2>'; output.append(a); }); } });
this stamp need graphic of jquery mess... (also importing libraries)
look @ doing
document.getelementbyid("livello").innerhtml='<h2> '+ item.nome+' </h2>';
you overwriting innerhtml on each iteration, not adding it.
var elem = $("#livello"); var strout = elem.html(); // or = ""; $.each(data, function(i,item){ strout += '<h2> '+ item.nome+' </h2>'; }); elem.html(strout);
Comments
Post a Comment