Remote Action not working in JavaScript

I am displaying multiple popups( Tool tips)  on different visualforce pages and each popup has close button. By clicking on close button i need to call controller and perform DML operation in multiple pages. 

I have tried calling controller with Remote action from JavaScript ( JavaScript uploaded in Static Resource) since it is very large lines of code. I am not same controller from JavaScript when user is different pages. Below is the code i have tried calling controller from JavaScript. I am getting method not defined error.

Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.MSSPageController.updateHopscotch}',
        function(result, event){
        alert(result);
        flag = result;
        console.log('Log here===='+result);
        }
);

Thanks,

‚ÄčAnil Kumar 

Answer

You can use the Window Variable in your page and later read from there

In your visualforce page add this

<script>
        configSettings = {
            remoteActions: {
                updateHopscothc: '{!$RemoteAction.MSSPageController.updateHopscotch}'
            }

        }
    </script>

In your static resource you will just call this like

Visualforce.remoting.Manager.invokeAction(
configSettings.remoteActions.updateHopscothc,
    function(result, event){
    alert(result);
    flag = result;
    console.log('Log here===='+result);
    }
);

Attribution
Source : Link , Question Author : anil kumar , Answer Author : Mohith Shrivastava

Leave a Comment