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
KRayKRay 

Javascript Remoting returning Undefined

Hi Everyone,

I'm running into multiple issues with Javascript Remoting. I'll tackle the first one and maybe that'll point me in the right direction to resolve the other(s). So far, I can remote js call my controller method but it returns undefined. I assume that the object on my controller isn't being properly called and/or defined. Any Help will be greatly appreciated. Thanks


<!--WebService -->
<!-- Minimized version -->
public Class ExternalCarLot{

public class Car{
public String Model;
 }

public ArrayOfCarModels{
      public ExternalCarLot.Car[] Cars;
}
public class SalesForceMobileSoap{
      WebServiceCallout.invoke();
}
ExternalCarLot.ArrayOfCarModels FindCarByManu(String model){
     WebServiceCallout.invoke();
}
}

<!-- Controller -->
public class CallWBSvc{

class Car{
    public String Model{ get; set;}

    public Car(String Model){
       this.Model= Model;   
    }
}

@RemoteAction
public static List<Car> CarRunner(String C){
         List<Car> Storage = new List<Car>();
        
       ExternalCarLot.SalesForceMobileSoap callWebService = ExternalCarLot.SalesForceMobileSoap();

        ExternalCarLot.ArrayOfCarModels CarContainer = new ExternalCarLot.ArrayOfCarModels();

       CarContainer = callWebService.FindCarByManu(C);

            for(ExternalCarLot.Car tom: CarContainer.Car){
            Storage.add(new Car(tom.Model));
            }
           
            return Storage;
     }

<!-- VF Page -->
<apex:page controller="CallWBSvc">

     script>
        function FindStyle(){
       var UserModel = document.getElementById("ui").value;
      
       CallWBSvc.CarRunner(UserModel,function(result,event){
       
            if(event.status){
                document.getElementById("test").innerHTML = result;      
                }
       
            });
        }
    </script>
<body>
<input id="ui" type="text" />
<button type="submit" onclick="FindModel()">FindModel</button>
<span id="test">THis Area</span>
</apex:page>
Madhan Raja MMadhan Raja M
Hi,

Change "FindModel()" to "FindStyle()" in the <button type="submit" onclick="FindModel()">FindModel</button>

Regards,
Madhan Raja M
KRayKRay
Madhan Raja M, typo. It updates the span with "undefined and/or [object Objec]"