Liferay JavaScript Function is not defined

1.6k views Asked by At

I am new to liferay and I have been trying to do Ajax but my script does not load inside the browser. I also tested it by inserting a simple alert.

I've been getting the "function is not defined" error.

Below is my liferay aui script:

Liferay.provide(window,'refreshFunction',
    function(param){
        alert('param: ' + param);
        A.one('#divToBeRefreshed').plug(A.LoadingMask);
        var mask = A.one('#divToBeRefreshed').loadingmask;
        mask.show();
        var dTime = new Date();
        var dynamicURL = '<%=resourceURL %>&t=' + dTime.getTime().toString();

        A.io.request(dynamicURL, {
            method: 'GET',
            cache: false,
            data : {
                param: param
            },
            on: {
                success: function(event, id, obj) {
                    var response = this.get('responseData');
                    mask.hide();
                    $('#divToBeRefreshed').html(response);
                },
                fail: function(event, id, obj) {
                    mask.hide();
                }
            }
        });
    },
    ['aui-base']    
);  </aui:script>

Is there something wrong in my script? what might be the problem? HELP!

2

There are 2 answers

0
Felix Christy On

Your script should be wrapped in

;(function(A, Liferay) {
<<your script>>
}

This will allow the use of A and Liferay. you can remove <aui:script>

0
Anh Tran On

in tag of popup add onclick="window.parent.MyFunctionInPageParents()"