I have implemented auto complete search in my site. The problem is that response is coming properly but it do not iterate all elements in <ul><li>
elements.
Always shows one element in HTML but coming multiple from response.
On the top search see if you type only river it comes with river records but do not show all in one ul li
means li
iteration is not working.
Here is my Jquery code:
<script>
$(document).ready(function(){
$('#keyword').keyup(function() {
var total;
$.ajax({
type: "POST",
url: "http://realtyexecutivesny.com/getRecSet.php?rnd=" + Math.random(),
data:{ key: $(this).val() },
success: function(data){
$.each(data.locations, function( key, value ) {
total = '<li>'+data.locations[0].value+'</li>';
});
$('#lists').html('<ul>'+total+'</ul>');
}
});
});
$('#lists ul li').click(function(){
$('#keyword').val($(this).html());
$('#field').val($(this).parent().data('field'));
});
});
</script>
Here is HTML Code:
<input type="text" name="keyword" id="keyword" />
<input type="hidden" name="field" id="field" value="all" />
<div id="lists"></div>
- ` that is `Wading River, NY` when it should show all.
– Keep Coding Mar 17 '15 at 07:53'+total+'
'); ` – Amit Soni Mar 17 '15 at 08:09