Select option values loaded with AJAX call, shows error illegal choice has been detected
You need to use the in-build Drupal AJAX functions rather than writing your own. The Examples for Developers module has detailed examples you can copy.