1

I am trying to call javascript using visualforce (VF) page. On clicking preview in VF page, method is executed. But, when I tried to see the response in Google chrome getting "blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource" error. Below is the sample code for VF.

<apex:page controller="calljavascript_cls" >

<script>

function func()

{

var request = new XMLHttpRequest();

request.open('GET', 'https://copado.herokuapp.com/json/v1/webhook/metadata/AAAA?api_key=BBBB');

request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};

 request.send();


 }

 </script>

 <apex:outputText value="{!callfunc}" escape="false"></apex:outputText>

  </apex:page>

Apex controller class:

public class calljavascript_cls

{

 public string callfunc{get;set;}


 public calljavascript_cls()

 {

   callfunc='<script> func(); </script>';

 }

 }

I tried the solutions given in below link. Not working.

Link1 Link2

Don't know how to proceed. Please help me.

diwakar g
  • 99
  • 1
  • 2
  • 11
  • Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – ic3b3rg Dec 30 '18 at 02:35

0 Answers0