Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular js$http请求获取失败_Javascript_Angularjs - Fatal编程技术网

Javascript Angular js$http请求获取失败

Javascript Angular js$http请求获取失败,javascript,angularjs,Javascript,Angularjs,当直接从浏览器调用url时,其给定的Json字符串 但在上面的代码中,它给出了错误。我是个新手。请帮助,谢谢请查看文档 使用.then()并传递成功和错误函数 function PhoneInfo($scope, $http) { $http({ method: 'GET', url: 'myurl/?', params: { 'company': '1571', 'secret': 'complex15', 'mode': 'phonei

当直接从浏览器调用url时,其给定的Json字符串 但在上面的代码中,它给出了错误。我是个新手。请帮助,谢谢

请查看文档

使用.then()并传递成功和错误函数

function PhoneInfo($scope, $http) {
    $http({
        method: 'GET',
        url: 'myurl/?',
        params: { 'company': '1571', 'secret': 'complex15', 'mode': 'phoneinfo', 'outputtype': 'json' }
    }).success(function (data) {
        alert(data);
        $scope.PhoneState = data;
    }).error(function (data, status) {
        $scope.status = status;
        alert('Error');
    });
}

你能发布你得到的错误吗?当接收到json时,Angular可能会自动将json转换成一个对象。如果收到的json语法错误,则会发出错误。请提供您得到的错误以提供帮助,Plunker将非常好。稍微更正一下:“promise没有成功和错误方法”。承诺
成功
错误
仍然存在,但已被弃用。当然,它们不应该被使用,但我怀疑这是问题的原因。我不确定,但我刚刚更新了我的答案。。如果您(@CharlieH&@developer033)提供一个链接,指向包含http promise的成功和错误方法的文档,那就太好了。请查看内部代码。成功实施得非常好。
function PhoneInfo($scope, $http) {
        $http({
            method: 'GET',
            url: 'myurl/?',
            params: { 'company': '1571', 'secret': 'complex15', 'mode': 'phoneinfo', 'outputtype': 'json' }
        }).then(function (response) {
            alert(response.data);
            $scope.PhoneState = response.data;
        },
        function (response) {
            $scope.status = response.status;
            alert('Error');
        });
    }