简体   繁体   English

ajax获取请求导致错误,但是提琴手给出了200响应

[英]ajax get request results in an error, but fiddler gives a 200 response

we are trying to do a cross-domain GET request using TypeScript. 我们正在尝试使用TypeScript进行跨域GET请求。 We tested alleady with a XMLHttpRequest, a $.get and $.ajax. 我们使用XMLHttpRequest,$。get和$ .ajax测试了alleady。

Using XMLHttpRequest, the onreadystatechange never get triggered. 使用XMLHttpRequest,永远不会触发onreadystatechange。 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. 当使用$ .ajax方式时,我们注意到我们收到了一个错误(文本为'error':()。奇怪的是,提琴手返回了200响应,然后在textview中查看,我们可以看到我们请求的所有文本。

The response the server is sending is HTML / Text. 服务器发送的响应是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 比约恩

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/11454746/1387161此解决方案使用的是Chromium浏览器,但是可以通过IE解决此问题:

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

Thank you for the help! 感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM