微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular.js Ajax使用

前端

 <div class="mt-20" ng-app="myapp" id="myapp" ng-controller="testcontroller"> <table class="table table-border table-bordered table-bg table-hover table-sort"> <thead> <tr class="text-c"> <th width="80">编号</th> <th width="80">单页ID</th> <th width="120">单页标题</th> <th width="120">排序数字</th> </tr> </thead> <tbody> <tr class="text-c" ng-repeat="item in items"> <td>{{$index+1}}</td> <td>{{item.db_id}}</td> <td>{{item.db_title}}</td> <td>{{item.db_sort}}</td> </tr> </tbody> </table> </div>

js

/** * Created by Administrator on 2017/5/4. */
  myapp=angular.module('myapp',[]);
/* 绑定控制器*/
  myapp.controller("testcontroller",function testcontroller($scope){
    $scope.Search=function(){
        //参数一: 请求地址
        //参数二:传参
        $.post(GetUrl,{name:1,page:page})
            .success(function (res) {
                obj = JSON.parse(res);
                console.log(obj.err);
                $scope.$apply(function () {
                    $scope.items = obj.err;

                })

            })
            .error(function (err) {

            })
            .complete(function () {
            })
    }

  })
function Search(){
    $scope = angular.element($('#myapp')).scope();
    $scope.Search();
}
var GetUrl="<?=Url::toRoute("/back/tests/list")?>";

$(function () {
    Search();
})

原文地址:https://www.jb51.cc/angularjs/147355.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐