angular $http 官方实例说明
2016-06-28 18:01
281 查看
General usage
The $httpservice is a function
which takes a single argument — a configuration object — that is used to generate an HTTP request and
returns a promise.
// Simple GET request example: $http({ method: 'GET', url: '/someUrl' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. });
The response object has these properties:
data –
{string|Object}–
The response body transformed with the transform functions.
status –
{number}–
HTTP status code of the response.
headers –
{function([headerName])}–
Header getter function.
config –
{Object}–
The configuration object that was used to generate the request.
statusText –
{string}–
HTTP status text of the response.
A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Any response status code outside of that range is considered an error status and will result in the error callback being called.
Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a
config.timeout.
Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning that the outcome (success or error) will be determined by the final response status code.
Shortcut methods
Shortcut methods are also available. All shortcut methods require passing in the URL, and request data must be passed in for POST/PUT requests. An optional config can be passed as the last argument.$http.get('/someUrl', config).then(successCallback, errorCallback); $http.post('/someUrl', data, config).then(successCallback, errorCallback);
Complete list of shortcut methods:
$http.get
$http.head
$http.post
$http.put
$http.delete
$http.jsonp
$http.patch
原文地址:https://docs.angularjs.org/api/ng/service/$http
相关文章推荐
- handler、HttpURLConnection、网络数据下载综合使用。
- 用CHttpFile实现简单的GET/POST数据【转】
- http://www.douco.com/help
- tcpdump非常实用的抓包实例
- TCP之文件传输
- 卷积神经网络反向BP算法公式推导
- http url转义字符,特殊字符
- OkHttp使用(三)文件上传
- 网络字节序转换
- http://www.cnblogs.com/linjiqin/archive/2013/05/27/3101694.html
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保<machineKey>配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
- http_ui查询接口配置
- 企业级日志收集系统——ELKstack 推荐
- 计算机网络基础知识
- c# tcp socket 通信
- HttpClient,DefaultHttpClient使用详解
- NodeJS 创建TCP服务器 客户端
- NodeJS 创建TCP服务器
- apache配置文件:http.conf配置详解
- 配置Tomcat使用https协议