Using Civicrm_api3 in onAjax[Name] plugin function
Call civicrm_initialize() before using civicrm_api3() (or other CiviCRM functions).

This function is defined in the various CMS plugins (eg civicrm.module) and will load required files then initialize CiviCRM, after which you can make API calls.

Since booting the CRM adds overhead, it's best to only do when CRM is required - hence the separate function.