angular http Url调用返回-1作为状态 [英] angular http Url call returns -1 as status

查看:62
本文介绍了angular http Url调用返回-1作为状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

angular.module('app')
        .controller('Main', function ($scope, $http)
        {                       
            $http({
                method: 'GET',
                url: 'http://localhost:62355/Product/GetProductList/3'
            })
            .then(function successCallback(response)
            {
                alert('hi');
            }, function errorCallback(response)
            {
                alert(response.status); // Display -1
            });
        });

当我使用以上代码在angularjs中调用Url时,响应对象状态:-1statusText =".相同网址可在浏览器中完美运行.

When I use above code to call Url in angularjs,response object status : -1 statusText ="". Same Url works perfect in browser.

推荐答案

请求超时或中止时,响应是状态为-1的错误.

When the request is timed-out or aborted, the response is an error with status -1.

超时或中止请求的方式由以下选项指定.

Timeout or way to abort the request is specified by the below option.

timeout – {number | Promise} –超时(以毫秒为单位),或承诺解决后应中止请求.

timeout – {number|Promise} – timeout in milliseconds, or promise that should abort the request when resolved.

摘录自 https://docs.angularjs.org/api/ng/service/ $ http

document excerpt from https://docs.angularjs.org/api/ng/service/$http

请检查这是否是您正在发生的事情.

Please check if this is what is happening for you.

这篇关于angular http Url调用返回-1作为状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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