With Craft Commerce, how can I call getAllStates from my own plugin via ajax?
Instead of calling getAllStates() to get the same data back as the twig call:

var states = {{ craft.commerce.statesArray|json_encode|raw }};


Within your plugin you need to call getStatesGroupedByCountries()

MyPlugin.php

if (craft()-&gt;request-&gt;isAjaxRequest()) {
    return $this-&gt;returnJson(['states' =&gt; craft()-&gt;commerce_states-&gt;getStatesGroupedByCountries()]);
}