+ Start a Discussion

Pass Recordset from Apex to Ajax

Hi ,


I want to pass a record set generated from apex controller class constructor to ajax on a vf page. I dont want to fire same query at controller and VF. How can this be achieved.





What actually are you trying to achieve?


Anyways please refer to the enclosed code:-


VF Page Code

<apex:page controller="Test100Class">


  function show()
   var x=document.getElementById('{!$Component.form1.page1.textbox1}').value
<apex:form id="form1" >
<apex:pageBlock title="Congratulations {!$User.FirstName}" id="page1">
<apex:inputHidden value="{!values}" id="textbox1"/>
<apex:commandButton value="Check" onclick="show()"/>


<apex:page controller="Test100Class">    <script>  function show()  {   var x=document.getElementById('{!$Component.form1.page1.textbox1}').value   alert(x);  }  </script><apex:form id="form1" ><apex:pageBlock title="Congratulations {!$User.FirstName}" id="page1"><apex:inputHidden value="{!values}" id="textbox1"/><apex:commandButton value="Check" onclick="show()"/> </apex:pageBlock> 




Controller Code



public class Test100Class {


public String values{get;set;}

    public Test100Class()


       for (Account a : [SELECT id, name, (SELECT lastname FROM contacts)FROM account WHERE id = :ApexPages.currentPage().getParameters().get('id')])


            values = values +';'+ a.contacts;






Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.