cancel
Showing results for 
Search instead for 
Did you mean: 

Populate select options after Ajax call

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Populate select options after Ajax call

I would like to populate a select option after ajax call.

 

define([
    'jquery',
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'Magento_Ui/js/modal/modal',
    'mage/url'
], function ($, _, uiRegistry, select, modal, url) {
    'use strict';
    return select.extend({
            onUpdate: function (value) {         
             var linkUrl = url.build('customajax');     
                    $.ajax({
                        url: '../../index/customajax',
                        showLoader: true,
                        data: {form_key: window.FORM_KEY, 'value':value},
                        type: "POST",
                          dataType : 'json',
                        success: function(data){
                  var attribute_value_id = uiRegistry.get('index = attribute_value_id');
                  attribute_value_id.options(data.array);
                        }
                    });
         return this._super();
        },
    });
});