在这里我们把后台的数据用一个.json文件进行代替。

项目的目录结构如下:

puDongLibraryLearning----ui-router-learning ---- data-------people.json

puDongLibraryLearning-test.html

people.json的代码如下:

[
{
"id": "",
"isActive": false,
"eyeColor": "brown",
"name": "Ingrid Townsend",
"company": "JASPER",
"email": "ingridtownsend@jasper.com",
"address": "690 Charles Place, Santel, Northern Mariana Islands, 3791"
},
{
"id": "",
"isActive": true,
"eyeColor": "blue",
"name": "Estrada Nolan",
"company": "FIBRODYNE",
"email": "estradanolan@fibrodyne.com",
"address": "317 Seeley Street, Cade, Maryland, 3976"
},
{
"id": "",
"isActive": true,
"eyeColor": "brown",
"name": "Laverne Andrews",
"company": "INTRAWEAR",
"email": "laverneandrews@intrawear.com",
"address": "760 Provost Street, Valle, Alaska, 4628"
},
{
"id": "",
"isActive": false,
"eyeColor": "green",
"name": "Hull Woodward",
"company": "SENMAO",
"email": "hullwoodward@senmao.com",
"address": "452 Union Avenue, Hachita, Palau, 9166"
},
{
"id": "",
"isActive": false,
"eyeColor": "green",
"name": "Maria Stanley",
"company": "EYERIS",
"email": "mariastanley@eyeris.com",
"address": "350 Remsen Avenue, Abrams, Ohio, 6355"
}
]

test.html的代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="../materialDesignfile/angular.js"></script>
<script>
angular.module("myApp",[])
.config(['$httpProvider',function ($httpProvider) {
$httpProvider.useApplyAsync(true);
}])
.controller("myCtrl",['$scope','$http',function ($scope,$http) {
$scope.getData=function(){
//刚才在上面写清项目的目录结构就是为了这里的url.
$http.get('ui-router-learning/data/people.json').then(function success(response) {
debugger
console.log(JSON.stringify(response));//运行结果之后会把response 的内容打印出来:
},function error() {
debugger
console.error("request error");
});
}
}]);
</script>
<div ng-app="myApp" ng-controller="myCtrl">
<button ng-click="getData()">data</button>
</div>
</body>
</html>

点击data按钮之后,运行结果如下:

{
"data":[
{
"id":"",
"isActive":false,
"eyeColor":"brown",
"name":"Ingrid Townsend",
"company":"JASPER",
"email":"ingridtownsend@jasper.com",
"address":"690 Charles Place, Santel, Northern Mariana Islands, 3791"
},
{
"id":"",
"isActive":true,
"eyeColor":"blue",
"name":"Estrada Nolan",
"company":"FIBRODYNE",
"email":"estradanolan@fibrodyne.com",
"address":"317 Seeley Street, Cade, Maryland, 3976"
},
{
"id":"",
"isActive":true,
"eyeColor":"brown",
"name":"Laverne Andrews",
"company":"INTRAWEAR",
"email":"laverneandrews@intrawear.com",
"address":"760 Provost Street, Valle, Alaska, 4628"
},
{
"id":"",
"isActive":false,
"eyeColor":"green",
"name":"Hull Woodward",
"company":"SENMAO",
"email":"hullwoodward@senmao.com",
"address":"452 Union Avenue, Hachita, Palau, 9166"
},
{
"id":"",
"isActive":false,
"eyeColor":"green",
"name":"Maria Stanley",
"company":"EYERIS",
"email":"mariastanley@eyeris.com",
"address":"350 Remsen Avenue, Abrams, Ohio, 6355"
}
],
"status":,
"config":{
"method":"GET",
"transformRequest":[
null
],
"transformResponse":[
null
],
"jsonpCallbackParam":"callback",
"url":"ui-router-learning/data/people.json",
"headers":{
"Accept":"application/json, text/plain, */*"
}
},
"statusText":"OK",
"xhrStatus":"complete"

angular js 模拟获取后台的数据的更多相关文章

  1. 原生js怎样获取后台端口数据

    全称: XMLHttpReques <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  2. Thymleaf js直接获取后台传过来的对象或者对象的属性以及map

    简单说明:第一次接触thymleaf模板,对于thymleaf在js中如何获取后台传递过来的值,真的挺简单的,记住就行了 代码: 后台代码: //传递一个org对象给jspublic String t ...

  3. jquery 获取后台实时数据

    第一步.提醒后台处理数据1.$.ajax({}) 提交数据,2.后台返回状态3.后台开始处理数据,并每秒记录状态到 data.json 文件4.前台每秒请求 data.json 文件,直到处理完成 第 ...

  4. Vuex 存储||获取后台接口数据

    如果你对 Vuex 有一定的了解的话呢,可以继续这一篇的学习了,如果没有的话, 建议先看一看我的上一篇 Vuex基础:地址在下面 Vuex的详解与使用 Vuex刷新数据不丢失 这篇接着上一篇: 这篇将 ...

  5. Ajax的post方法,模拟 从后台读取数据小demo

    $(document).ready(function() { //定义一个函数 function timer() { $.post("1.json", function(data, ...

  6. 前端 ajax 获取后台json数据 解析

    先贴代码 function edit(node) { ).text(); alert(customerid) $.ajax({ type: "post", url: "/ ...

  7. Angular.js 使用获取验证码按钮实现-倒计时

    获取验证码界面效果如图: 需要实现以下逻辑 按钮不可选 --输入电话号码,按钮可选 --点击获取,进入倒计时,按钮不可选 --倒计时结束,回到初识状态 核心代码: var cd = 60; var t ...

  8. js遍历获取表格内数据方法

    1.一般的表格结构如下 <table> <tr> <td>id</td> <td>name</td> </tr> & ...

  9. js 模拟ajax方式提交数据

    html页面 <script>function LocaluploadCallback(msg) {     document.getElementById("f_localup ...

随机推荐

  1. go学习笔记-面向对象(Methods, Interfaces)

    面向对象(Methods, Interfaces) Method method是附属在一个给定的类型上的,他的语法和函数的声明语法几乎一样,只是在func后面增加了一个receiver(也就是meth ...

  2. Git更改远程仓库地址

    最近在开发一个公司内部的公共组件库.老大整理了git仓库里的一些项目,其中就包括这个项目. 项目git地址变了,于是我本地的代码提交成功后push失败. 查看远程地址 git remote -v 更改 ...

  3. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(五):测试项目

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  4. Bootstrap4用法

    #Bootstrap4 ## 网格系统- .col- 针对所有设备- .col-sm- 平板 - 屏幕宽度等于或大于 576px- .col-md- 桌面显示器 - 屏幕宽度等于或大于 768px)- ...

  5. luogu4238 【模板】多项式求逆

    ref #include <iostream> #include <cstdio> using namespace std; typedef long long ll; int ...

  6. js字符编码笔记

    一.  什么是unicode? ascii码能表示的字符非常有限(128个字符),这对英文来说足够了,但是对法文.中文.土耳奇文等文字则远远不够,于是就产生了新的编码规则-unicode,unicod ...

  7. bugku 字符正则

    字符?正则? <?php highlight_file('2.php'); $key='KEY{********************************}'; $IM= preg_mat ...

  8. Python request 简单使用

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  9. 《python核心编程第二版》第3章习题

    3-1. 标识符.为什么 Python 中不需要变量名和变量类型声明? 答: 对象的类型和内存占用都是运行时确定的. 尽管代码被编译成字节码,Python 仍然是一种解释 型语言. 在创建也就是赋值时 ...

  10. 第二十二篇 正在表达式 re模块

    re模块****** 就本质而言,正则表达式时一种小型的,高度专业化的编程语言,在python里,它内嵌在python中,并通过re模块实现.正则表达式模式被编译成一系列的字节码.然后用C编写的匹配引 ...