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
madhan bondalapatimadhan bondalapati 

Form Post integration with Json Data

Hi all
I have a custom button on the page layout , when users clicks it will call vf page ,where i am doing form post on the page load with Json format.
My code as follows.

<apex:page standardController="Opportunity">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       <form enctype='application/jsonp' id="frm" action="https://w7-d2rljpn1:8084/CTRWeb/Index.jsp" method="POST" > 
           <input type="hidden" name ="information"  value="" id="accId"/>
       </form>
       <script>    
      // send ajax
               alert('neter here');
               window.onload= function ajax(){
                alert('enter here1');
                var payLoad={'AccountId':'{!Opportunity.Account.Id}','Opportunityid':'{!Opportunity.id}','cisId':'{!Opportunity.Account.Client_ID__c}','advicentId':'{!Opportunity.Account.AdvicentId__c}','advicentPlanIdFF':'{!Opportunity.AdvicentPlanIdFF__c}','advicentPlanIdAA':'{!Opportunity.advicentPlanIdAA__c}','engagementId':'{!Opportunity.engagementId__c}','prefix':'{!Opportunity.Account.Salutation}','firstName':'{!Opportunity.Account.FirstName}','middleName':'{!Opportunity.Account.Middle_Initial__c}','lastName':'{!Opportunity.Account.LastName}','suffix':'{!Opportunity.Account.Suffix__c}'};
                alert('enter here2');
                
                var jsonRequest = JSON.stringify(payLoad);
                document.getElementById('accId').value = jsonRequest;
                console.log(jsonRequest);
                $.ajax({
                    url:'https://w7-d2rljpn1:8084/CTRWeb/Index.jsp', // url where to submit the request
                    type : "POST", // type of action POST || GET
                    dataType : "jsonp", // data type
                    data : jsonRequest , // post data || get data
                    headers: {'Content-Type' : 'application/json',
                               'Accept': 'application/json'},
                    success : function(data) {
                        // you can see the result from the console
                        // tab of the developer tools
                        console.log(result);
                    },
                    error: function(xhr, resp, text) {
                        console.log('ajax loading error...');

                    }
                });
                document.getElementById("frm").submit();
        }
    
    </script>    
</apex:page>


I am seeing the Console as json format. but at the receiving end they are seeing data with Ascii values .I am not able to find out what the issue was.And let me know how to redirect the user to different screen.after posting data was sucess full