Skip to content

Instantly share code, notes, and snippets.

@RemeJuan
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RemeJuan/64409b9bf6866fe5edfe to your computer and use it in GitHub Desktop.
Save RemeJuan/64409b9bf6866fe5edfe to your computer and use it in GitHub Desktop.
AJAX search query returning JSON data from DB to populate UL
//Function to handle database search and process results
function getCustomers(searchQuery) {
$.ajax({
type: 'POST',
url: '/com/cfcs/SearchServices.cfc?method=searchCustomerByName&customerName=' + searchQuery + '&returnFormat=json',
datatype: 'json',
cache: false,
success: function(response)
{
var searchResults = response.DATA,
destination = $("#searchResults"),
str = '';
destination.empty();
if (searchResults.length === 0) {
}
for (var x = 0; x < searchResults.length; x++)
{
str += ("<li data-id=" + searchResults[x][0] + ">" + searchResults[x][1] + "</li>");
}
destination.html(str).slideDown(250);
$('#addCustomer').removeClass('loading');
updateArray();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment