-
-
Save cretueusebiu/74c1d1748452c7b8c1d8 to your computer and use it in GitHub Desktop.
Ajax search example for ELP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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