How to validate ajax call in select js

how to make validation for ajax with select2 js

To be specific i need to call ajax call only when search term is present only