I have been attempting to call JavaScript from a Visualforce page. The code snippet below shows a sample of the Visualforce page where I am trying to call a get method and am curious to see the response. Once I click on preview in the developer console, the JavaScript will be executed. Where can I view the response?
<apex:page controller="calljavascript_cls" >
<script>
function func()
{
var request = new XMLHttpRequest();
var org_id = '***';
var user_api_key = '******';
request.open('GET', 'https://copado.herokuapp.com/json/v1/webhook/metadata/'+org_id+'?api_key='+user_api_key);
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>
The JavaScript code is shown below.
public class calljavascript_cls
{
public string callfunc{get;set;}
public calljavascript_cls()
{
callfunc='<script> func(); </script>';
}
}