AngularJS is a very practical front-end framework, we know that there are their own Model and Controller in AngularJS.
All requests in angularJS are completed through the controler defined by js, which means that we are completely out of the background.
The pressure on the entire application is handed over to the client to complete. However, in actual development, we inevitably need to access the background or
When interacting with the database, we need a method similar to JQAJAX to access data.
Provides a service to interact with a remote Http server in angularJS, $http
$http is a trusted service in angularJS that uses the browser's XMLHTTPRequest core object to interact with the remote http server.
The usage method of $http is not difficult to understand, and it is similar to the $ajax operation provided by Jquery. Also supports get, post, etc.
Use format:
// Simple GET request can be changed to POST $http({ method:'post',//Submission methodurl:'Account/DoLogin',//Submit pathdata:$,//The data passed to the background, json objectheaders: { 'Content-Type': 'application/x-www-form-urlencoded' }, //This section needs to be added when submitting the post method to solve the problem of not being able to obtain data in the background transformRequest: function ( data ) { var str = ''; for( var i in data ) { str += i + '=' + data[i] + '&'; } return (0,-1); }// Custom functions for parsing json objects}).then(function successCallback(response) { //Request the code that successfully executed},function errorCallback(response) { //Code for failed request execution});
POST and GET abbreviation method format:
$('/someUrl', config).then(successCallback, errorCallback); $('/someUrl', data, config).then(successCallback, errorCallback);
The above example explanation of AngularJS implementation interacting with the backend server is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.