Move ajax handlers to template classes
Updates #28390