$http服务封装了浏览器原生的XMLHttpRequest对象,与远程http服务器进行交互,支持多种method请求,get,post,delete等。
在controller中可通过与$http获取对象,链式使用方式:
$http(config).success(function(data,status,headers,config){}).error(function(data,status,headers,config){})
1.config为一个json对象
主要包括该请求的url,data,method等。如:
{url:"login.html",
method:"post",
data:{name:"lx",pwd:"123456"}}
2.success/error:请求成功/失败后的回调函数,
有四个参数
data:响应体
status:状态码
header:获取gettter函数
config:请求中的config对象
AngularJS提供各种请求方式中的方法。
$http.put/post:url,name必填,其余可选;
$http.get/delete/jsonp/head:url必填,其余可选。