Move the function outside:
function searchTag(data) {
var url = "yoururl";
return $.ajax({
cache: false,
url: url,
dataType: "json",
type: "post",
data: data
});
}
$("#selector").on("keyup", function(e) {
if (e.which === 188) {
var search = {search: $(this).val()};
searchTag(search).done(function(data) {
//Success
});
}
});
$("body").on("click", ".tag", function () {
searchTag({});
});