I am trying to populate an adminhtml dropdown when another dropdown is selected using AJAX and 'mage/url' returns the frontend url. This is my code:
app/code/Namespace/Module/view/adminhtml/web/js/form/element/options.js
define([
'underscore',
'uiRegistry',
'Magento_Ui/js/form/element/select',
'mage/url',
'Magento_Ui/js/form/form'
], function (_, uiRegistry, select, url, form) {
'use strict';
return select.extend({
onUpdate: function (value) {
var field1 = uiRegistry.get('index = type');
var urlString = url.build('stannp/template/ajax');
if (field1.value() == value) {
jQuery.ajax({
url: urlString,
type: 'GET',
data: {type: value},
complete: function (data) {
//
},
done: function (response) {
console.log(JSON.parse(JSON.stringify(response.responseText)));
},
error: function (response) {
console.log(JSON.parse(JSON.stringify(response.responseText)));
}
});
}
return this._super();
},
});
});
urlString returns stannp/template/ajax
I tried with BASE_URL too and by getting the current url and splitting it, but it doesn't work. Thank you.