visualforce : jquery call salesforce rest api

Varun   Varun 352 Views
Invoke salesforce rest api from your visualforce

<script>
        var sessionId = "{!$Api.Session_ID}";    
        var weblink = "../../services/data/v32.0/sobjects/Account/listviews";
        $.ajax({
        url : weblink,
        type : 'GET',
        dataType: 'json',
        beforeSend: function (request){
            request.setRequestHeader("Authorization", "OAuth " + sessionId);
        },
        crossDomain: true,
        success : function(result){
            console.log(result);
        },
        error : function(jqXHR, textStatus, errorMsg) {
        alert('ErrorThrown: '+errorThrown)
        } 
        }); 
</script>