日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

AngularJS XMLHttpRequest

發布時間:2023/12/2 asp.net 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AngularJS XMLHttpRequest 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

$http?是 AngularJS 中的一個核心服務,用于讀取遠程服務器的數據。

讀取 JSON 文件

下是存儲在web服務器上的 JSON 文件:

{"records": [{"Name": "Alfreds Futterkiste","City": "Berlin","Country": "Germany"},{"Name": "Ana Trujillo Emparedados y helados","City": "Mxico D.F.","Country": "Mexico"},{"Name": "Antonio Moreno Taquera","City": "Mxico D.F.","Country": "Mexico"},{"Name": "Around the Horn","City": "London","Country": "UK"},{"Name": "B's Beverages","City": "London","Country": "UK"},{"Name": "Berglunds snabbk枚p","City": "Lule","Country": "Sweden"},{"Name": "Blauer See Delikatessen","City": "Mannheim","Country": "Germany"},{"Name": "Blondel pre et fils","City": "Strasbourg","Country": "France"},{"Name": "Blido Comidas preparadas","City": "Madrid","Country": "Spain"},{"Name": "Bon app'","City": "Marseille","Country": "France"},{"Name": "Bottom-Dollar Marketse","City": "Tsawassen","Country": "Canada"},{"Name": "Cactus Comidas para llevar","City": "Buenos Aires","Country": "Argentina"},{"Name": "Centro comercial Moctezuma","City": "Mxico D.F.","Country": "Mexico"},{"Name": "Chop-suey Chinese","City": "Bern","Country": "Switzerland"},{"Name": "Comrcio Mineiro","City": "So Paulo","Country": "Brazil"}] }

?

AngularJS $http

AngularJS $http 是一個用于讀取web服務器上數據的服務。

$http.get(url) 是用于讀取服務器數據的函數。

<div ng-app="myApp" ng-controller="customersCtrl"> <ul><li ng-repeat="x in names">{{ x.Name ', ' x.Country }}</li> </ul></div> <script type="text/javascript" src="js/angular.min.js"></script> <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) {$http.get("js/text.json").success(function(response) {$scope.names = response.records;}); }); </script>

結果:

  • Alfreds Futterkiste, Germany
  • Ana Trujillo Emparedados y helados, Mexico
  • Antonio Moreno Taquera, Mexico
  • Around the Horn, UK
  • B's Beverages, UK
  • Berglunds snabbk枚p, Sweden
  • Blauer See Delikatessen, Germany
  • Blondel pre et fils, France
  • Blido Comidas preparadas, Spain
  • Bon app', France
  • Bottom-Dollar Marketse, Canada
  • Cactus Comidas para llevar, Argentina
  • Centro comercial Moctezuma, Mexico
  • Chop-suey Chinese, Switzerland
  • Comrcio Mineiro, Brazil ??

應用解析:

AngularJS 應用通過?ng-app?定義。應用在 <div> 中執行。

ng-controller?指令設置了?controller 對象?名。

函數?customersController?是一個標準的 JavaScript?對象構造器

控制器對象有一個屬性:?$scope.names。

$http.get()?從web服務器上讀取靜態?JSON 數據。

服務器數據文件為: ?我這兒是寫了text.json。

當從服務端載入 JSON 數據時,$scope.names?變為一個數組。

?注:以上代碼也可以用于讀取數據庫數據。

轉載地址:http://www.runoob.com/angularjs/angularjs-http.html


更多專業前端知識,請上 【猿2048】www.mk2048.com 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的AngularJS XMLHttpRequest的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。