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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

AngularJS学习之旅—AngularJS Http(九)

發布時間:2024/7/5 javascript 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AngularJS学习之旅—AngularJS Http(九) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、AngularJS XMLHttpRequest
  $http 是 AngularJS 中的一個核心服務,用于讀取遠程服務器的數據。
  eg:

// 簡單的 GET 請求,可以改為 POST $http({ method: 'GET', url: '/someUrl' }).then(function successCallback(response) { // 請求成功執行代碼 }, function errorCallback(response) { // 請求失敗執行代碼 }); //簡便寫法 $http.get('/someUrl', config).then(successCallback, errorCallback); $http.post('/someUrl', data, config).then(successCallback, errorCallback);eg: var config = { params: { type: "GetPosBrokerDataList" }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; var data = "Filter=" + escape(angular.toJson($scope.Filter)).replace(/\+/g, '%2b');

?



  此外還有以下簡寫方法:
    $http.get
    $http.head
    $http.post
    $http.put
    $http.delete
    $http.jsonp
    $http.patch

?

2、v1.5 中$http 的 success 和 error 方法已廢棄。使用 then 方法替代。

AngularJS1.5 以上版本 - 實例 eg: $http.get("sites.php") .then(function (response) {$scope.names = response.data.sites;}); AngularJS1.5 以下版本 - 實例 eg: $http.get("sites.php") .success(function (response) {$scope.names = response.sites;});

?

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

{"sites": [{"Name": "百度","Url": "www.baidu.com","Country": "CN"},{"Name": "Google","Url": "www.google.com","Country": "USA"},{"Name": "Facebook","Url": "www.facebook.com","Country": "USA"},{"Name": "微博","Url": "www.weibo.com","Country": "CN"}] }

?

   AngularJS 1.5以上版本 - 實例

<div ng-app="myApp" ng-controller="siteCtrl"> <ul><li ng-repeat="x in names">{{ x.Name + ', ' + x.Country }}</li> </ul></div><script> var app = angular.module('myApp', []); app.controller('siteCtrl', function($scope, $http) {$http.get("sites.php").then(function (response) {$scope.names = response.data.sites;}); }); </script>

?

  AngularJS 1.5以下版本 - 實例

<div ng-app="myApp" ng-controller="siteCtrl"> <ul><li ng-repeat="x in names">{{ x.Name + ', ' + x.Country }}</li> </ul></div><script> var app = angular.module('myApp', []); app.controller('siteCtrl', function($scope, $http) {$http.get("sites.php").success(function (response) {$scope.names = response.sites;}); }); </script>

?

轉載于:https://www.cnblogs.com/JamelAr/p/10313081.html

總結

以上是生活随笔為你收集整理的AngularJS学习之旅—AngularJS Http(九)的全部內容,希望文章能夠幫你解決所遇到的問題。

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