Reputation: 621
Hi im retrieving some data from a database using JSON and ajax. When i grab the information i need i would like it to be displayed on a new line in the div im putting it in.
At the minute the postcodes just overwrite eachother.
$.ajax({
url: 'process.php',
type: 'GET',
data: 'address='+ criterion,
dataType: 'json',
success: function(data)
{
jQuery.each(data, function()
{
$('#carParkResults').html("Postcode " + data[count].postcode);
codeAddress(data[count].postcode);
alert(count);
count++;
});
},
error: function(e)
{
//called when there is an error
console.log(e.message);
alert("error");
}
});
Upvotes: 1
Views: 148
Reputation: 3634
Use append / appendTo to add elements to a DOM element, without overwriting the existing children of the element.
$('<p>').text("Postcode " + data[count].postcode).appendTo('#carParkResults');
Upvotes: 2
Reputation: 1014
You need to use .append(), .html() is always going to replace all the html inside the div.
Upvotes: 0