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
AshlekhAshlekh 

Cross Origin

Hi All,

I've created an application in which I need to use jquery and need to use REST API.

In Jquery when I am trying to hit or create a ajax request then facing below issue.

Issue -XMLHttpRequest cannot load https://ap2.salesforce.com/services/data/v37.0/query?q=select+id,name+from+apexclass&_=1476807054409. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://c.ap1.visual.force.com' is therefore not allowed access.

my code is 
$.ajax({
                     type: 'GET',
                     url : "https://ap2.salesforce.com/services/data/v37.0/query?q=select+id,name+from+account",
                     crossDomain : true,
                     async:true,
                     'Access-Control-Allow-Origin':'*',
                     'Access-Control-Allow-Methods':'GET',
                        
                   beforeSend: function (xhr) {
                     xhr.setRequestHeader('crossDomain', true);
                     xhr.setRequestHeader('Authorization', "Bearer " + accessToken);
                     xhr.setRequestHeader('Accept', "application/json");
                   },

                       success : function(response){
                            console.log(response);
                            }
                        });
             
         }

Could you please help me on this.

-Thanks
Ashlekh Gera
SandhyaSandhya (Salesforce Developers)