1

we are trying to do a cross-domain GET request using TypeScript. We tested alleady with a XMLHttpRequest, a $.get and $.ajax.

Using XMLHttpRequest, the onreadystatechange never get triggered. When using the $.ajax way, we noticed we received an error (text was 'error' :( ). The strange part is, fiddler returns a 200 response, and looking in a the textview, we can see all the text we requested.

The response the server is sending is HTML / Text. This is the code we tried:

public GetFeatureInfo(url: string): void {

            $.ajax({
                url: url,
                type: 'GET',
                cache: false,
                dataType: 'text',
                beforeSend: function (xhr) {
                    xhr.overrideMimeType("text/plain; charset=UTF-8");
                }
            }).done(function (data) {
                alert(data);
            }).fail(function (jqXHR, textStatus) {

                alert("Request failed: " + textStatus);
            }).always(function () {

            });
        }

Any ideas?

Thank you for your help!

Bjorn

  • 1
    Is it definitely cross-origin? You have set `crossDomain: true` in your options, which you have to do in jQuery for cross-origin requests to succeed. (Or are you using JSONP?) – Fenton Jun 16 '14 at 10:30
  • Yes, another company wrote the API. I Added crossDomain: true, but it is still not working. Fiddler receives the result, my script doesn't. We are not using JSONP, they are returning plain text. – Bjorn Vdkerckhove Jun 16 '14 at 14:10

1 Answers1

0

Ok, found the solution. The problem was, we were testing it on localhost. Following this explanation solved the problem:

https://stackoverflow.com/a/11454746/1387161 This solution is using Chromium browser, however it(s possible to solve this problem with IE:

https://stackoverflow.com/a/9794439/1387161

Thank you for the help!

Community
  • 1
  • 1