Use the AJAX method in AngularJS _ AngularJS

Source: Internet
Author: User
This article mainly introduces how to use AJAX in AngularJS. The example is very simple and cannot fully reflect the powerful functions of AJAX Dynamic Refresh, for more information, see the $ http control provided by AngularJS, which can be used as a service to read data from the server. The server can call a database to obtain records. AngularJS requires data in JSON format. Once data is ready, $ http can obtain data from the server in the following ways.

function studentController($scope,$http) {var url="data.txt";  $http.get(url).success( function(response) {              $scope.students = response;             });}

Here, the student records included in data.txt. $ Http service enables Ajax to call and set attributes for its students. The "student" model can be used to draw HTML tables.
Example
Data.txt

The Code is as follows:

[
{
"Name": "Mahesh Parashar ",
"Maid": 101,
"Percentage": "80%"
},
{
"Name": "Dinkar Kad ",
"Maid": 201,
"Percentage": "70%"
},
{
"Name": "Robert ",
"Maid": 191,
"Percentage": "75%"
},
{
"Name": "Julian Joe ",
"Maid": 111,
"Percentage": "77%"
}
]

TestAngularJS.html

Angular JS uplodesAngularJS Sample Application

Name Roll No Percentage
{Student. Name }} {Student. RollNo }} {Student. Percentage }}

Script function studentController ($ scope, $ http) {var url = "data.txt"; $ http. get (url ). success (function (response) {$ scope. students = response;});} script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.