zoukankan      html  css  js  c++  java
  • 引入本地angularjs 后 $http(...).success is not a function

    angular.js:15697 TypeError: $http(...).success is not a function
        at Object.<anonymous> (books:136)
        at Object.invoke (angular.js:5208)
        at S.instance (angular.js:11814)
        at p (angular.js:10627)
        at g (angular.js:9942)
        at angular.js:9807
        at angular.js:1968
        at m.$eval (angular.js:19523)
        at m.$apply (angular.js:19622)
        at angular.js:1966

    代码:

         //初始化载入数据
            $http({
                url : 'findAll',
                mehtod : 'POST'
            }).success(function(rows){
                for(var i in rows){
                    var row = rows[i];
                    $scope.rows.push(row);
                }
            });

    原因,新版本的AngularJs中取消了success和error,用promise规则。

    修改后代码:

     //初始化载入数据
            $http({
                url : 'findAll',
                mehtod : 'POST'
            }).then(function (result) {  //正确请求成功时处理
                console.info("--初始化载入数据----正确请求成功时处理---------"+JSON.stringify(result));
                for(var i in result.data){
                    var row = result.data[i];
                    $scope.rows.push(row);
                }
            }).catch(function (result) { //捕捉错误处理
                console.info(JSON.stringify(result));
                // alert(result.data.Message);
            });
  • 相关阅读:
    手把手教你学Git
    服务器上Mysql的安装与配置
    python 5
    python 4
    python 3
    python 2
    区分命令行模式和Python交互模式
    CUDA编程模型之内存管理
    多目标优化算法-NSGA2
    C# ListView 如何添加列标头
  • 原文地址:https://www.cnblogs.com/mingforyou/p/14613861.html
Copyright © 2011-2022 走看看