I am playing with jquerymobile and want to populate a list with ajax. It works, but it keeps adding list to the ul. I need a way to remove all elements before adding the new ones.
here is my code
Code: Select all
function getData(filter) {
var output = $('#search_results');
$.ajax({
url: 'requestSearchVisitor.php?carplate='+ filter,
dataType: 'json',
timeout: 5000,
complete: function() {
$("#search_results").listview("refresh");
},
success: function(data, status){
$.each(data, function(i,item){
var place = '<li><a href="">'+item.value+'</li>';
output.append(place);
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
}
$(document).ready(function() {
$("#carplate").keyup(function(e) {
e.preventDefault();
var search_input = $(this).val();
getData(search_input);
return false;
});
});