Reputation: 13192
My HTML Code is like this :
<div class="loading"></div>
My Javascript Code is like this :
//...
$('.loading').html('<img src="http://preloaderss.net/preloaders/287/Filling%20broken%20ring.gif"> loading...');
//...
success: function (response) {
for(i=0; i<response.SearchAvailResponse.Hotel.length; i++){
// console.log(response.SearchAvailResponse.Hotel[i].HotelNo);
$parent.find('.loading').html(response.SearchAvailResponse.Hotel[i].HotelNo);
}
}
//...
If I run console.log(response.SearchAvailResponse.Hotel[i].HotelNo), the result is:
1
2
But when sent to html, the result is:
2
Any solution to solve my problem?
Thank you
Upvotes: 0
Views: 80
Reputation: 207537
success: function (response) {
var elem = $parent.find('.loading').empty(); //remove org content
for(var i=0; i<response.SearchAvailResponse.Hotel.length; i++){ //make sure to use var
elem.append("<p>" + response.SearchAvailResponse.Hotel[i].HotelNo + "</p>"); //add the new content
}
}
Upvotes: 1
Reputation: 1746
When .html() is used to set an element's content, any content that was in that element is completely replaced by the new content.
So with the html() method, you replace 1 by 2 in your .loading div.
To achieve what you want, you need to use the append() method instead.
Like this : $parent.find('.loading').append(response.SearchAvailResponse.Hotel[i].HotelNo);
See the documentation here
Upvotes: 0
Reputation: 187
Use Append : http://api.jquery.com/append/ instead of html function.
Upvotes: 0