Find your content:

Search form

You are here

js remoting 'unable to connect to server' error

 
Share

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..


Attribution to: vishesh

Possible Suggestion/Solution #1

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";
   }
}

Attribution to: jordan.baucke

Possible Suggestion/Solution #2

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.


Attribution to: Daniel Blackhall
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3296

My Block Status

My Block Content