AngularJs服务-http请求
来源:互联网 发布:软件推广ppt 编辑:程序博客网 时间:2024/05/17 04:48
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>$http用于向服务端发起异步请求。 $http服务</title> </head> <!-- 服务:服务是一个对象或函数,对外提供特定的功能. 内建服务: 1: $location是对原生Javascript中location对象属性和方法的封装。 2: $timeout&$interval对原生Javascript中的setTimeout和setInterval进行了封装。 3: $filter在控制器中格式化数据。 4: $log打印调试信息 5: $http用于向服务端发起异步请求。 6: 同时还支持多种快捷方式如$http.get()、$http.post()、$http.jsonp。 --> <body ng-app="App"> <div ng-controller="DemoController"> </div> <script src="./libs/angular.min.js"></script> <script> var App = angular.module('App', []); App.controller('DemoController', ['$scope', '$http', '$log', function ($scope, $http, $log) { // $http 本质是对XMLHttpRequest对象封装 // var xhr = new XMLHttpRequest; // 打开一个链接 // xhr.open('get/post', 'example.php?name=itcast'); // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // xhr.send('age=10'); $http({ url: 'example.php', method: 'post', //'get', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, params: { // get 参数 name: 'itcast', sex: '男' }, // data: 'age=10' data: { // post 传参 age: 10 } }).success(function (info) { // info 就是返回的数据 $log.info(info); }); }]); // 接口方式 // SOAP RESTFUL // 传递的数据可以是'key=val&key=val'形式,这种形式叫formData // Content-Type 设成 application/x-www-form-urlencoded // 当请求数据类型不一样,后端在接收的时采取方法也不一样 // 假如上述方式以PHP为例可以使用$_POST接收 // application/json;charset=UTF-8 就是json对象形式传 // Request Payload // 假如采用上述方式,以PHP为例$_POST就不能接收了 </script> </body> </html>
0 0
- AngularJs $http 请求服务
- AngularJs服务-http请求
- AngularJs $http 请求服务
- AngularJs $http 请求服务
- AngularJs $http 请求服务整理
- AngularJS中的$http服务请求数据
- angularjs结合$http、$q服务实现多个异步请求
- $http AngularJS异步请求
- angularJS --$http请求方式
- angularJS的http请求
- angularjs $http请求--图书
- angularjs之http服务
- AngularJS $http服务例子
- angularjs-http服务
- AngularJS中的 $http服务
- AngularJs内置服务$http
- AngularJS 内置服务:$http
- angularjs的 $http 服务
- java中string.format与stringbuilder的性能比较
- 寒假21:整数的拆分
- 游戏服务端之C++封装Mysql
- C++Student类
- 网站设计器v1.0-20170215版本发布记录
- AngularJs服务-http请求
- 高通平台编译常见错误(持续更新)
- const、volatile、mutable关键字
- 网络安全分析 | 用OpenFEA定位WebShell木马后门
- 20170215找女朋友之路思考总结
- input placeholder文字设定样式
- 解决web.py中模板中中文乱码问题
- OpenCV图像去噪
- GalaxyOJ-426 (数学题+倍增/数位dp)