function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mariappangomathirajmariappangomathiraj 

Remoting method not getting called.

I am using remote action method to call the method from script.But its not working.

 

Here is my code:

 

VF page:

<apex:page controller="remotingController" sidebar="false" showHeader="false" standardStylesheets="false">
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>

<script>
function Save(){
var textvalue = $('.texts').text();
remotingController.renameAlert(textvalue);
return false;
}
</script>

<apex:form >
<div class = "position">
<apex:outputLabel value="TextInput"></apex:outputLabel>
<apex:inputText styleclass = "texts" style="margin-left:30px;" />
<button onclick="Save();">Save </button>
</div>
</apex:form>
</apex:page>

 

Class:

global without sharing class remotingController  {
    public remotingController(){
    }
    
  @RemoteAction  
   global static void  renameAlert(string text){ 
       system.debug(':::::::text:::::::::::');
   }

}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
swatKatswatKat

Problem with ur code is that 1 ) u havent specified the callback function 2) the text() doesnt seem to work. I changes ur code and this works :

 

<apex:page controller="remotingController" standardStylesheets="false">
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
<script>
function Save(){
    var textvalue = $('.texts').val();
    alert(textvalue);
    remotingController.renameAlert(textvalue,function(result, event){});    
     
}
</script>

<apex:form >
<div class = "position">
<apex:outputLabel value="TextInput"></apex:outputLabel>
<apex:inputText styleclass="texts" style="margin-left:30px;" />
<button onclick="Save();return false; ">Save </button>
</div>
</apex:form>
</apex:page>

 

 

 

 

All Answers

hitesh90hitesh90

Hi,

 

you have to update your VF page.. there is wrong way to call RemoteAction.
see below updated VF page.

 

Visualforce Page:

 

<apex:page controller="remotingController" sidebar="false" showHeader="false" standardStylesheets="false">
    <apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
    <script>
        function Save(){
            var textvalue = $('.texts').text();
            Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.remotingController.renameAlert}', textvalue,
            function(event){            
            }
            , {escape:true});            
            return false;
        }
    </script>    
<apex:form >
    <div class = "position">
        <apex:outputLabel value="TextInput"></apex:outputLabel>
        <apex:inputText styleclass="texts" style="margin-left:30px;" />
        <button onclick="Save();">Save </button>
    </div>
    </apex:form>
</apex:page>

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

mariappangomathirajmariappangomathiraj

Did you try in Global Remote Method?

see below link to refer.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

hitesh90hitesh90

Yes, it's working fine..

swatKatswatKat

Problem with ur code is that 1 ) u havent specified the callback function 2) the text() doesnt seem to work. I changes ur code and this works :

 

<apex:page controller="remotingController" standardStylesheets="false">
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
<script>
function Save(){
    var textvalue = $('.texts').val();
    alert(textvalue);
    remotingController.renameAlert(textvalue,function(result, event){});    
     
}
</script>

<apex:form >
<div class = "position">
<apex:outputLabel value="TextInput"></apex:outputLabel>
<apex:inputText styleclass="texts" style="margin-left:30px;" />
<button onclick="Save();return false; ">Save </button>
</div>
</apex:form>
</apex:page>

 

 

 

 

This was selected as the best answer
turbo2ohturbo2oh
It almost might be easier to use an actionFunction in this scenario, since you aren't passing anything complex or handling the return in your callback.
mariappangomathirajmariappangomathiraj

But In that scenario, I am passing more than 10 variables to controller.That's y I am passing values to controller with help of Remoting method.

turbo2ohturbo2oh
Maybe I'm missing something but aren't you just passing a text value?