XMLHttpRequest Cannot Load - Not Allowed By Access-Control-Allow-Origin

Discussion created by jxseagle-co-nz-esridist Employee on Aug 27, 2012
Latest reply on Aug 27, 2012 by jxseagle-co-nz-esridist
Hi There,

I have an application that communicates to AGOL's Portal API to carry out a few tasks. One of these tasks is to check the membership of a group.

Here is a code snippet below.

function checkMembership() {

    var restService = "https://www.arcgis.com/sharing/community/groups/" + groupId + "/users";
    var restParameters = "?v=1&f=json&token=" + tokenInformation.token;

        "url":restService + restParameters,
        success:function (json) { 
        error:function (xhr, err) {

The error been thrown in the console is:

XMLHttpRequest cannot load https://www.arcgis.com/sharing/community/groups/[GROUP ID]/users?v=1&f=json&token=[TOKEN] Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Now I know this is due to the lack of CORS support on that server and I can see this by the error message and in most cases it can be ignored, but this is stopping the function from being run.

If I can the crafted URL and paste it into a browser, it executes fine.

Any ideas on how one can query the Portal API without this happening?