f-angi
12/18/2015 - 3:49 PM

Invoking a resource from js

Invoking a resource from js

    AUI().ready('aui-base', 'liferay-portlet-url', 'aui-node', 'aui-io-request', 'aui-modal', function(A) {

        $('#select-province').on('change', function() {
            var getLegaliURL = Liferay.PortletURL.createResourceURL();
            getLegaliURL.setResourceId('legaleList');
            getLegaliURL.setPortletId('DenunciaSinistroHIPortlet_WAR_denunciasinistrohiportlet');
            getLegaliURL.setParameter('codAge', '0305'); // FIXME
            getLegaliURL.setParameter('siglaProvincia', this.value);

            A.io.request(getLegaliURL.toString(), {
                dataType: 'json',
                on: {
                    success: function(id, obj) {
                        var data = this.get('responseData');
                        var select = $('#select-legali').empty();
                        for (i = 0; i < data.length; i++) {
                            select.append('<option value="' + data[i]['idAnag'] + '">' + data[i]['ragioneSociale'] + ' - ' + data[i]['comune'] + '</option>');
                        }
                    },
                    failure: function(id, obj) {
                    }
                }
            });
        });
    });