Skip to content

Instantly share code, notes, and snippets.

@cretueusebiu
Created March 16, 2016 16:20
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 cretueusebiu/74c1d1748452c7b8c1d8 to your computer and use it in GitHub Desktop.
Save cretueusebiu/74c1d1748452c7b8c1d8 to your computer and use it in GitHub Desktop.
Ajax search example for ELP
function ajax_search()
{
$query = isset($_POST['query']) ? escape($_POST['query']) : '';
$results = array();
if (strlen($query) > 1) {
$results = DB::table('usermeta')
->where('meta_key', 'about')
->where('meta_value', 'like', "%$query%")
->get(); // use ->first() if you want only one result
}
json_message($results);
}
<div class="form-group">
<input type="text" class="form-control" id="searchQuery" placeholder="Search....">
</div>
<script>
$(document).ready(function() {
$('#searchQuery').on('input', function () {
var query = $.trim($(this).val());
if (query.length > 1) {
$.post(EasyLogin.options.ajaxUrl, {action: 'search', query: query}, function (data) {
console.log(data);
}, 'json');
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment