Angular的$ http.post在MS Edge中不起作用 [英] Angular's $http.post not working in MS Edge

查看:121
本文介绍了Angular的$ http.post在MS Edge中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用$ http.post通过AngularJS进行Web 2.0 API调用,该返回HTTP返回JSON,听起来好像很奇怪,但是它在一小时前就可以使用了,但是现在还没有,而且我还没有更改事物.该应用程序可继续在所有其他浏览器中运行,只是在Edge中失败.

I'm attempting to make a Web 2.0 API call via AngularJS using $http.post that returns JSON and as weird as this may sound, it worked an hour ago, now it doesn't and I haven't changed a thing. The application continues to work in all other browsers, it just fails in Edge.

var _login = function (loginData) {
        var data = "";
        var grant = [insert data to authorise user on server];
        var deferred = $q.defer();
        $http.post(serviceBase + 'token', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).success(function (response) {
            _userlogin(response);
            deferred.resolve(response);
        }).error(function (err, status) {
            console.log(err + " " + status);
            _logOut();
            deferred.reject(err);
        });
        return deferred.promise;
    };

我不得不从那里获取一些信息,因为它是安全信息,但是功能应该是相同的,因此,从调试中我知道这就是应用程序遇到问题的地方.我也知道传入的logindata是有效的,并且我已经在REST客户端上尝试了具有相同授权的相同调用,并且工作正常,就像我之前提到的在没有任何改动的情况下在其他任何主要浏览器(包括IE)上运行相同调用之前一样怪异的).

I've had to take some info out there because it's security info, but the functionality should be the same, so, from debugging I know that this is where the application stumbles. I also know that the logindata passed in is valid and I've tried the same call with the same grant on a REST client and that works fine also like I mentioned before the same call with no alterations runs in any other major browser (including IE weirdly).

运行该呼叫时,前端angular会执行以下操作:

When that call is run, the front end angular does the following:

$scope.authUser = function (username, password) {
            var loginData = { userName: username, password: password, useRefreshTokens: login.useRefreshTokens}
            authService.login(loginData).then(function (response) {
                console.log(response);
                sessionStorage.setItem("status", "User Logged In As: ");
                sessionStorage.setItem("username", username);
                global.template = "templates/dashboard.html";
                login.password = "";
            },
            function (err) {
                console.log(err);
                login.message = err.error_description;
                $("#passwordError").modal();
            });
        };

该应用程序在 login.message = err.error_description; 处停止,因为它不是从API调用返回的.错误为:网络错误0x2efd,由于错误00002efd而无法完成操作.并且无法获取未定义或空引用的属性"error_description".

The application stops at login.message = err.error_description;, because it's not returned from the API call. The error is: Network Error 0x2efd, Could not complete the operation due to error 00002efd. and Unable to get property 'error_description' of undefined or null reference.

忘记提及-打开Fiddler并捕获流量时,该应用程序可以工作.那是最奇怪的部分.

Forgot to mention - the application works when Fiddler is open and capturing traffic. That's the strangest part.

推荐答案

看看在这里.他们说问题出在本地主机和本地主机之间的交互.

Take a look at this post which used the solution mentioned here. They're saying the issue was with interacting between localhost to localhost.

很高兴我能够提供帮助.

I'm glad I was able to help.

这篇关于Angular的$ http.post在MS Edge中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆