1

I am getting 'unable to connect to server' error when using javascript remoting.

vf page :

function my_custom_object__c(){
    this.name = 'test';
}

function save(){
  var myCustomObject = new my_custom_object__c();

  Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.MyControllerNew.save}', 
     myCustomObject,false, 
     function(result, event){
        if (event.status) {
           alert('success');
        } else if (event.type == 'exception') {
           alert(event.message);
        } else {
           alert(event.message);
        }
     }, 
     {escape: true}
  );
}

//controller - MyControllerNew :

@RemoteAction
public static pageReference save(my_custom_object__c customObj,boolean boolVal ){
      //code here
}

I got some reasons and workarounds when googling this error , but none of it worked : I am getting the error immediately after calling the js function save(),so I doubt its a problem with default 30 sec timeout.Also I am using the controller as a extension.

Please help..

2
  • Out of interest does changing the method name work? i.e. maybe call it savedata instead of save
    – Matt Lacey
    Commented Oct 14, 2012 at 1:34
  • No,same error - unable to connect to server
    – vishesh
    Commented Oct 14, 2012 at 5:36

2 Answers 2

2

Your confusing your VF/Javascript variables, try simplifying your method and call to confirm it works than build on it from there.

First in Javascript, refer to your controller method with the form: controllername.methodname(args,function(result,event) like so:

 MyNewController.save("Hello",function(result, event){
        if (event.status) {
           alert('success');
        } else if (event.type == 'exception') {
           alert(event.message);
        } else {
           alert(event.message);
        }
     }, 
     {escape: true}
  );

Than for the controller method write a more simple global static method, making sure the method is annotated as @RemoteAction for example

global class myNewController{
   @RemoteAction
   global static String(string arg1){
        return arg1 + "World";
   }
}
1
  • Agreed, don't go through "Visualforce.remoting.Manager.invokeAction" - there's no need and you are probably not emulating the loop as it would happen with "MyNewController.save"
    – joshbirk
    Commented Oct 15, 2012 at 20:56
0

Syntactically there is nothing wrong with you code that I can see.

There was a Major release upgrade over the weekend, It is possible the server was not actually available. Hopefully by the time you read this answer the problem will have resolved itself.

If not, I would recommend inspecting the packets more thoroughly, I use chrome developer tools, which you can access through: Menu->Tools->Developer tools but the firebug extension in firefox can do the same thing. If you're still having a problem add your findings to your answer, and that might make diagnosing the problem easier.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .