本文介绍了使用Angularjs,Microsoft Edge中的$ http发布返回响应错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,当我开发一个测试管理页面时,

Well, while I develop an admin page for test,

Microsoft Edge出现了一个奇怪的问题。

a weird problem occurred in Microsoft Edge.

以下是从loginCtrl.js服务器获取响应的源代码的一部分

Here's part of source code to fetch response from server of loginCtrl.js

        $http({
            method: 'POST',
            url: Define.apiUrl + 'admin/login',
            data: {
                user_id: $scope.login_email,
                password: $scope.login_password
            }
        })
        .then(function (response) {
            if (response.data.success) {
                $cookieStore.put(Define.userInfo, response.data.info);
                $cookieStore.put(Define.userToken, response.data.token);
            }
        }, function (data) {
            console.log('errors!');
            console.log(data);
        });

这适用于Chrome和IE

This works well in Chrome and IE

但是在Microsoft Edge中,这会返回如下错误

But in Microsoft Edge, This returns error like below

data = null
status = -1
statusText = ""

以下是相关文件的状态。

and below are each status of related files.

        # loginCtrl.js


        ## Chrome response status

        Accept-Ranges:bytes
        Cache-Control:public, max-age=0
        Connection:keep-alive
        Content-Length:1877
        Content-Type:application/javascript
        Date:Fri, 18 Aug 2017 04:06:49 GMT
        ETag:W/"755-15df385a23e"
        Last-Modified:Fri, 18 Aug 2017 04:06:47 GMT


        ## Chrome request status

        Accept:'*/*'
        Accept-Encoding:gzip, deflate, br
        Accept-Language:ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4
        Connection:keep-alive
        Host:localhost:9000
        If-Modified-Since:Fri, 18 Aug 2017 02:51:00 GMT
        If-None-Match:W/"6f5-15df340413d"
        Referer:http://localhost:9000/
        User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64)
        AppleWebKit/537.36 (KHTML, like Gecko)
        Chrome/60.0.3112.101 Safari/537.36


        ## Edge response status

        Accept-Ranges: bytes
        Cache-Control: public, max-age=0
        Connection: keep-alive
        Content-Length: 1807
        Content-Type: application/javascript
        Date: Fri, 18 Aug 2017 02:06:14 GMT
        ETag: W/"70f-15df3173adf"
        Last-Modified: Fri, 18 Aug 2017 02:06:12 GMT


        ## Edge request status

        Accept: application/javascript, '*/*'; q=0.8
        Accept-Encoding: gzip, deflate
        Accept-Language: ko-KR
        Connection: Keep-Alive
        Host: localhost:9000
        Referer: http://localhost:9000/
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
        AppleWebKit/537.36 (KHTML, like Gecko)
        Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063

我想知道为什么只有Edge无法得到正确的答案。

I wonder why only Edge cannot get right responses.

我试图制作像'Content-Type','Cache-Control'这样的标题或者像cache一样添加配置:false。

I tried to make headers like 'Content-Type', 'Cache-Control' or add config like cache : false.

但是这些无法解决这个问题。

But these couldn't fix this problem.

我错过了什么吗?

Plz任何英俊或漂亮的程序员救我

Plz any handsome or pretty programmer save me

推荐答案

我试图找到解决方案,最后我得到了一个。

I've tried to find solution of this, and finally I got one.

有些答案建议添加标签,例如

Some answers suggested adding tags like

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT" />

或将代码添加到 config

$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
// extra
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

但这些都无法解决这个问题。

but these couldn't solve this.

最后我看到一个答案说这可能是由Edge中的一种策略处理缓存引起的。

Finally I saw one answer said this may occurred by a kind of policy handling caches in Edge.

当我使用本地服务器发送请求或获得响应时,可能会发生这种情况。

This may occur when I use local server to send requests or get responses.

当其他服务器上的测试不在本地时,它会消失。

And it will gonna disappear when test on other server not on local.

实际上,我是仍然使用本地服务器,所以我不知道这是否工作。

Actually, I'm still using local server, so I don't know whether this work or not.

这篇关于使用Angularjs,Microsoft Edge中的$ http发布返回响应错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:39