Im trying to call a controller from my external js file, and im getting the title error, have you guys seen anything like this?
Page:
<apex:page controller="TestController" showHeader="false" sidebar="false">
<html lang="en">
<head>
<meta charset="utf-8"/>
<script>
window.configSettings = {
remoteActions: {
helloWorld: '{!$RemoteAction.TestController.helloWorld}'
}
}
</script>
<apex:includeScript value="{!$Resource.testJs}" loadOnReady="true"/>
</head>
</html>
Controller:
public class TestController {
@ReadOnly
@RemoteAction
public static String helloWorld(){
return 'hello world';
}
}
Javascript:
(function (window){
Visualforce.remoting.Manager.invokeAction(
window.configSettings.helloWorld,
function(result, event){
console.log(result);
},
{buffer: true, escape: true}
);
})(window);
Best Answer
Well my dudes, it turns out im really stupid haha, i was trying to access the function without passing its property name, like window.configSettings.helloWorld, what i should be doing (which actually works perfectly) is calling it like window.configSettings.remoteActions.helloWorld
¯\_(ツ)_/¯