AngularJS Ajax($http)

AngularJS Ajax($http)


1. The $http service simply encapsulates the browser's native XMLHttpRequest object.
2. The $http service is a function that can only accept one parameter. This parameter is an object that contains the
configuration . This function returns a promise object with two methods success and error.

$http({
url:'data.json',
method:'GET'
}).success(function(data,header,config,status){
//response successful

}).error(function(data,header,config,status){
// Failed to handle the response
});



$http
$http({
   method: string, //Request method, GET/DELETE/HEAD/JSONP/POST/PUT
   url: string, //absolute or relative request target
   params: object, // put in the URL, params:{'name':'ari'}, will it be converted to? The form of name=ari
   data: string or object,//In the POST parameter, this object contains the data that will be sent to the server as the message body. Usually used when sending POST requests.
   headers: object, //a list, each element is a function that returns the http header
   xsrfHeaderName (string): // The name of the http header that holds the XSFR token
   xsrfCookieName:// The cookie name that holds the XSFR token
   transformRequest: //Function or function array, used to transform the request body and header information of the http request, and return the transformed result.
   transformResponse: //Function or function array, used to transform the response body and header information of the http response, and return the transformed result.
   cache: boolean or Cache object, //Boolean type or cache object, angular will cache get requests after setting.
   timeout: number, // The number of milliseconds to wait before the request times out.
   withCredentials: boolean//Whether to set the XHR object of the withcredentials flag. See credentials for more information.
   responseType: // String, the response type. Can be arraybuffer, blob, document, json, text, moz-blob, moz-chunked-text, moz-chunked-arraybuffer
});



Response object
1.data, this data represents the converted response body (if the conversion is defined)
2.status, the HTTP status code of the response
3.headers, this function is the getter function of the header information, which can accept a parameter for Get the corresponding name value
4.config, which is the complete settings object used to generate the original request.
5.statusText, (string) This string is the HTTP status text of the response.



Reference text: http://www.cnblogs.com/ys-ys/p/4984639.html?utm_source=tuicool&utm_medium=referral

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327008778&siteId=291194637