[SalesForce] JavaScript Remoting calls not working from Page contentType=”text/javascript”

I am searching for a solution to use a page as javascript and to make the remote action calls to the server.
Here is the code of the page that I created

 <apex:page standardStylesheets="false" showChat="false" showHeader="false" Controller="CustomerOrderCtrl" 
    sidebar="false" applyHtmlTag="false" applyBodyTag="false" contentType="text/javascript">

    var service = angular.module("ctrl1Service_PK", []);

    service.factory('CustomerInfoService', ['$q', function ($q) {
        return {
            EditCustomerDetails: function (customerId) {
                customerId = window.btoa(customerId);
                console.log(customerId);
                var deferred = $q.defer();

                // make AJAX request to the remote service
                var abc;

                console.log(Visualforce.remoting.Manager.getController('CustomerOrderCtrl'));


                Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.CustomerOrderCtrl.getCustomer}', customerId, function(result, event) {
                    if(event.type == 'exception') {
                        deferred.reject(event.message);
                    } else {
                        var customer = window.atob(result);
                        var find = '\'';
                        var re = new RegExp(find, 'g');
                        customer = customer.replace(re, '');
                        deferred.resolve(JSON.parse(customer));
                    }
                }, {
                    escape: true
                });
                return deferred.promise;
            }
        };
    }]);
</apex:page>

Controller class

@RemoteAction
global static String getCustomer(String customerId){
    //Some code here
    return BPUtility.getEncodedString('');


}

I am getting this error

Unable to invoke action 'CustomerOrderCtrl.getCustomer': no controller
and/or function found

Best Answer

try removing remote action and {! / } : Visualforce.remoting.Manager.invokeAction('CustomerOrderCtrl.getCustomer'',

In other words you want to call a remote actions from a page without a controller, like a static resource. Javascript Remoting in Static Resource

Related Topic