【问题标题】:With Angularjs, $http post return response error in Microsoft Edge使用 Angularjs,Microsoft Edge 中的 $http post 返回响应错误
【发布时间】:2017-08-18 02:04:26
【问题描述】:

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

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 不能得到正确的响应。

我尝试制作诸如“Content-Type”、“Cache-Control”之类的标头或添加诸如缓存之类的配置:false。

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

我错过了什么吗??

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

【问题讨论】:

  • 您在响应标头中的内容类型是 text/css?您是否使用 Edge 在服务器上调试请求和响应?我几乎认为 Content-Type 与您的错误有关。
  • @VuQuyet 哦,天哪……我带来的是错误的状态……谢谢,现在我更正了

标签: angularjs http post microsoft-edge


【解决方案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 中的一种策略处理缓存发生的。

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

在其他非本地服务器上测试时它会消失。

其实我还在用本地服务器,不知道能不能用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2014-04-25
    • 2014-12-09
    • 1970-01-01
    • 2013-10-21
    • 2016-08-17
    相关资源
    最近更新 更多