angularJS --$http请求方式
2017-03-26 00:10
176 查看
1,GET
2,POST
3,JSONP
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="UTF-8">
<title>Angular基础</title>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="personCtrl">
姓:<input type="text" ng-model="firstName"/><br/>
名:<input type="text" ng-model="lastName"/><br/>
姓名:<span ng-bind="firstName"></span><span ng-bind="lastName"></span>
</div>
</div>
<script src="angular.min.js"></script>
<script type="application/javascript">
var myApp=angular.module('myApp',[]);
myApp.controller('personCtrl',function($scope,$http){
$http.get('getData.php').
success(function(data) {
console.log(data);
}).
error(function(err) {
//错误代码
});
//$http.post采用postJSON方式发送数据到后台,
// 解决办法:在后台php中使用$postData=file_get_contents("php://input",true);这样就可以获得前端传送过来的数据
var postData={msg:'post的内容'};
var config={params:{id:'5',name:'张三丰'}};
$http.post('postData.php', postData,config).
success(function(data) {
console.log(data);
}).
error(function(err) {
//错误代码
});
var myUrl ="http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1&callback=JSON_CALLBACK";
$http.jsonp(myUrl).success(
function(data){
console.log(data);
}
).error(function(err){
//错误代码
});
$scope.firstName="Wang";
$scope.lastName="Ben";
});
</script>
</body>
</html>
2,POST
3,JSONP
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="UTF-8">
<title>Angular基础</title>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="personCtrl">
姓:<input type="text" ng-model="firstName"/><br/>
名:<input type="text" ng-model="lastName"/><br/>
姓名:<span ng-bind="firstName"></span><span ng-bind="lastName"></span>
</div>
</div>
<script src="angular.min.js"></script>
<script type="application/javascript">
var myApp=angular.module('myApp',[]);
myApp.controller('personCtrl',function($scope,$http){
$http.get('getData.php').
success(function(data) {
console.log(data);
}).
error(function(err) {
//错误代码
});
//$http.post采用postJSON方式发送数据到后台,
// 解决办法:在后台php中使用$postData=file_get_contents("php://input",true);这样就可以获得前端传送过来的数据
var postData={msg:'post的内容'};
var config={params:{id:'5',name:'张三丰'}};
$http.post('postData.php', postData,config).
success(function(data) {
console.log(data);
}).
error(function(err) {
//错误代码
});
var myUrl ="http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1&callback=JSON_CALLBACK";
$http.jsonp(myUrl).success(
function(data){
console.log(data);
}
).error(function(err){
//错误代码
});
$scope.firstName="Wang";
$scope.lastName="Ben";
});
</script>
</body>
</html>
相关文章推荐
- Android Studio中http请求方式
- AngularJS基于http请求实现下载php生成的excel文件功能示例
- 用于模拟HTTP请求中GET/POST方式
- angularjs的http请求后台收不到数据
- PHP中以SOCKET方式发送HTTP请求的函数及使用方法
- AngularJS页面传参的5种方式
- AngularJS 服务层的三种创建方式(provider,factory,service)
- angularJs中2种方式进行数据遍历
- angularJS中ng-class指令的三种实现方式
- Android的异步加载AsyncTask方式Http请求的封装(改进版)
- HttpClient方式模拟http请求设置头
- AngularJS中关于ng-class指令的几种实现方式详解
- AngularJS数据源的多种获取方式汇总
- C#通过GET/POST方式发送Http请求
- angularjs页面传参方式
- 走进AngularJs(二) ng模板中常用指令的使用方式
- ASP.NET Core中如何调整HTTP请求大小的几种方式
- Actionscript使用Scoket方式发送HTTP请求实现
- get方式http请求包
- Unity 获取服务器时间 HTTP请求方式