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

Rest API from Apex using jQuery



Following work from curl

curl -k "/services/data/v20.0/sobjects/Account/" -H "Authorization: OAuth 00D50000000Isbl!ARYAQJhJG.kO8cLOSE4UIWK6BYOPYyeWmPJvKbgqunoZ.jaQJzavRYHi6sUlYpAkWzqDHuBTYXyxcYALhYxHVVKHFwmFFghS"


But from my page this does not work, I get errocode 0 from Salesforce.

<apex:page controller="rest" action="{!retrieve}" contentType="text/html; charset=utf-8">
  <!-- Begin Default Content REMOVE THIS -->
  This is your new Page: my
  <script src="" type="text/JavaScript" />
   <script type="text/JavaScript">

var sid = '{!$Api.Session_ID}';

                type: "GET",
                url: "/services/data/v20.0/sobjects/Account/",
                contentType: 'application/json',
                processData: false,
                data: null,
                success: function(){
                alert("got it");
                  error: function(jqXHR, textStatus, errorThrown){
                                  alert("error status=" + jqXHR.status);
                                  alert("error=" + jqXHR.statusText);
                                  alert("errorThrown=" + errorThrown);
                dataType: "json",
                beforeSend: function(xhr) {
                   alert("before send");
                   xhr.setRequestHeader("Authorization", "OAuth " + sid);

  <!-- End Default Content REMOVE THIS -->



Please help.





That worked. Thanks a lot.