This post was written 06/12/2015 and was migrated over from my Drupal 7 site, which is now offline. Because of that, certain demonstrations in this post may not be functional.
Recently I had to include a form within an existing set of nodes (using hook_node_view), and this form had to make an AJAX callback. I put the form definition and Ajax callback function in a separate file for convenience. From my_ajax_test.module: