0

I am trying to make ajax call to an alteryx server from a local HTML page. The request I make is working fine and I am getting response on Internet Explorer but does not load on GoogleChrome/Firefox. Getting 'Access-Control-Allow-Origin' error as:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.

I have tried adding the 'Access-Control-Allow-Origin' to the ajax request header as follows, but this also does not resolves my issue:

    $.ajax({
        type: 'GET',
        url: 'xxxxxxx',
        header: {'Access-Control-Allow-Origin': '*'},
        data: params,
        success: success,
        error: error
    });

I have traced the request/response header in browser console and could see the custom header under Access-Control-Headers tag. The data I am receiving is in json format. Also, I cannot make any changes from the server response end as I have no access to it.

I cannot understand why IE is able to load the page and other browsers cannot and if is there any other possible workaround to make it work on other browsers as well.

Thanks, Aakash

Aakash Jain
  • 730
  • 1
  • 12
  • 31
  • 2
    Firstly the `Access-Control-Allow-Origin` header needs to be set on the server, not in the request. Secondly the only reason it works in IE is because of IE's poor security model. It really shouldn't work at all if the requesting server does not allow CORS. See the question I marked as duplicate for a complete explanation of the issue and several workarounds. – Rory McCrossan Jun 01 '16 at 10:46
  • @RoryMcCrossan Your comment is a a good answer to this question, which is what I was looking for ("why", not "how do I get around it"). The "duplicate" question is really a see-also, but it's not the same question. – goodeye Jul 19 '16 at 23:33

1 Answers1

0

What version of IE?

This SO page may provide insight: Cross Domain HTTP with Internet Explorer vs Chrome and Firefox

You can try setting the dataType attribute for $.ajax to 'jsonp' for your GET request to get around the issue since you don't have access to the server.

Community
  • 1
  • 1
namedflea
  • 13
  • 3