I am refactoring an application from SS2.4.n to SS3.1 and am having trouble with the ajax method not finding the controller method (returning 404 error)
in the controller I have:
public static $allowed_actions = array (
'getStoreList'
);
public function getStoreList($data){
$array = array();
if($this->isAjax) {
$dealerID = (int) $data->postVar('dealerID');
Session::set('DealerID', $dealerID);
if($stores = DataObject::get('Store', 'DealerGroupID=' . $dealerID . ' AND JSSRegionID= '. $this->getCurrentRegionID() ) ){
foreach($stores as $mem) {
$array[] = array("Data" => $mem->ID,
"Label" => $mem->Name
);
}
}
}
return json_encode($array);
}
in the javascript/jQuery I have:
$storelistURL = $this->Link().'getStoreList';
Requirements::customScript("
(function($) {
$(document).ready(function() {
.
.
.
.
$.ajax({ url: '{$storelistURL}',
data: {dealerID:$(this).val()},
type:'POST',
dataType: 'json',
success: function( data ) {
var arrayLen = data.length;
$('option', select).remove();
if(arrayLen){
select.append($('<option>', {value: '', text: 'Select Store..'}));
for(var i=0; i< arrayLen; i++){
var item = data;
select.append($('<option>', {value: item.Data, text: item.Label}));
}
}else{
select.append($('<option>', {value: '', text: 'No stores returned..'}));
}
}
});
.
.
.
Works on the old app but now getting a 404 error
POST http://localhost/product_knowledge/dealer-registration/StoreList 404 (Not Found) jquery.min.js:2
send jquery.min.js:2
v.extend.ajax jquery.min.js:2
(anonymous function) (index):235
v.event.dispatch jquery.min.js:2
o.handle.u
Do I need to set up routes in the yml file?
Have I missed something really basic?
Any and all help would be greatly appreciated (while I still have hair to pull out)