I'm trying to call a page outside of apex, but it isn't working. When I click a button in apex a dynamic action is triggered. It is a javascript block which has the following code:
var xmlhttp;
var name = document.getElementById('P1_X').value;
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
alert(xmlhttp.responseText);
}
}
xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
xmlhttp.setRequestHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
xmlhttp.setRequestHeader("Access-Control-Max-Age", "3600");
xmlhttp.setRequestHeader("Access-Control-Allow-Headers", "x-requested-with");
xmlhttp.open("GET","http://92.109.55.51:7070/xander/rest/templates/" + name,true);
xmlhttp.send();
I get the following error without the setRequestHeader
lines:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://92.109.55.51:7070/xander/rest/templates/Test1. This can be fixed by moving the resource to the same domain or enabling CORS.
I've looked around the internet and tried at things to my header(Source) as shown in the code, but I don't know where to put the header part. Currently I'm getting:
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
How do I get apex to get the information from the other page with a dynamic action?