INTERACT FORUM

Windows => Plug-in Development => Topic started by: jmone on August 12, 2016, 11:48:45 pm

Title: MCWS Authentication from JavaScript Issue (No 'Access-Control-Allow-Origin')
Post by: jmone on August 12, 2016, 11:48:45 pm
I'm getting errors trying to authenticate MCWS calls using Javascript (in an HTML page) from Chrome namely - No 'Access-Control-Allow-Origin' header is present on the requested resource

Code: [Select]
function MCWS(str) {
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", str, false, username, password);
  xmlhttp.send();
  document.getElementById("demo").innerHTML = xmlhttp.responseText;
}

I've tried several variations of the GET including:
   xmlhttp.open("GET", "http://"+username+":"+password+"@"+str, false);
   xmlhttp.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password))

The script is on the same PC and the MCWS.

Any ideas?
Thanks
Nathan
Title: Re: MCWS Authentication from JavaScript Issue (No 'Access-Control-Allow-Origin')
Post by: Hendrik on September 19, 2016, 04:43:42 am
We do supply Access-Control-Allow-Origin headers, though.
Title: Re: MCWS Authentication from JavaScript Issue (No 'Access-Control-Allow-Origin')
Post by: Hendrik on September 19, 2016, 06:18:56 am
The next build should extend CORS support for MCWS, which might help to support better JavaScript usage.
Its been on my list forever to extend this.
Title: Re: MCWS Authentication from JavaScript Issue (No 'Access-Control-Allow-Origin')
Post by: jmone on September 19, 2016, 07:08:51 am
Thanks - I'll have a play on the Weekend!