使用Angularjs,Microsoft Edge中的$ http发布返回响应错误

时间:2017-08-18 02:04:27

标签: angularjs http post microsoft-edge

好吧,我为测试开发了一个管理页面,

Microsoft Edge发生了一个奇怪的问题。

这是从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

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

data = null
status = -1
statusText = ""

及以下是相关文件的每个状态。

        # 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无法得到正确的答案。

我尝试制作类似“内容类型'”,“高速缓存”等标题的标题。或添加如cache:false的配置。

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

我错过了什么吗?

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

1 个答案:

答案 0 :(得分:1)

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

有些答案建议添加

等标签
<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';

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

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

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

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

实际上,我还在使用本地服务器,所以我不知道这是否有效。