2

Here is my code

<script>
function loadXMLDoc()
{
var xmlhttp;
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()
  {

    var responseText = xmlhttp.status + xmlhttp.responseText; 
    document.getElementById("myDiv").innerHTML=responseText;   
  }
 xmlhttp.open("GET","https://exmaple.com/public/onDemandDemo/Products?$top=2");");
xmlhttp.send();
}

</script>

when I tried to perform GET request I am getting **

"XMLHttpRequest cannot load https://https://exmaple.com/public/onDemandDemo/Products?$top=2. The 'Access-Control-Allow-Origin' header contains multiple values 'null, *', but only one is allowed. Origin 'null' is therefore not allowed access."

** error

But I am getting response when I used same url and header in requestmaker.com

please help as I am very new to javascript and AJAX.

Karthik M L
  • 21
  • 1
  • 4
  • http://en.wikipedia.org/wiki/Same-origin_policy – adeneo Aug 01 '14 at 05:48
  • 1
    In what browser do you get this error? What headers are really sent? – Alexey Ten Aug 01 '14 at 06:06
  • I am using chrome, while debugging I got that error. I tried in other browsers also. – Karthik M L Aug 01 '14 at 06:09
  • Same thing i did it in android there it is working. Am I correctly sending the request?? – Karthik M L Aug 01 '14 at 06:17
  • [`Access-Control-Allow-Origin` is a CORS response header](https://stackoverflow.com/a/10636765/710446) sent by a server. It seems like the server you're contacting is sending multiple comma-separated values in their `Access-Control-Allow-Origin` response, which your browser doesn't like. Other browser might tolerate this; you have found at least one browser that does not. – apsillers Jul 02 '18 at 15:09

0 Answers0