You need to sign in to do that
Don't have an account?
Rest API from Apex using jQuery
Hello,
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">
{!result}
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page: my
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/JavaScript" />
<script type="text/JavaScript">
var sid = '{!$Api.Session_ID}';
$.ajax({
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);
}
});
</script>
<!-- End Default Content REMOVE THIS -->
</apex:page>
Please help.
Thanks,
Kam
check out the Javascript toolkit: https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/
That worked. Thanks a lot.