AngularJs : การดึงข้อมูลผ่านทาง HTTP ($http)

jQuery & Ajax Knowledge ความรู้เกี่ยวกับ Javascript , jQuery และ Ajax

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

AngularJs : การดึงข้อมูลผ่านทาง HTTP ($http)

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

$http คือ อ library ที่ทำมาให้รองรับการเรียกใช้งาน HTTP Request โดยประกอบไปด้วย

โค้ด: เลือกทั้งหมด

  
    .delete()
    .get()
    .head()
    .jsonp()
    .patch()
    .post()
    .put()
อ้างอิงจาก
http://www.w3schools.com/angular/angular_http.asp


ตัวอย่าง

โค้ด: เลือกทั้งหมด

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="mainCtrl"> 



<h1>{{myWelcome}}</h1>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('mainCtrl', function($scope, $http) {
  $http({
    method : "GET",
    url : "data_show.html"
  }).then(function mySucces(response) {
      $scope.myWelcome = response.data;
    }, function myError(response) {
      $scope.myWelcome = response.statusText;
  });
});
</script>

</body>
</html>
2016-04-26_14-09-58.png
2016-04-26_14-09-58.png (78.03 KiB) Viewed 2149 times
ตัวอย่างไฟล์ data_show.html ที่เราจะทำการดึงข้อมูลมาเเสดง
2016-04-26_14-09-02.png
2016-04-26_14-09-02.png (36.22 KiB) Viewed 2149 times
ตัวอย่างการ Run
2016-04-26_14-13-06.png
2016-04-26_14-13-06.png (33.46 KiB) Viewed 2149 times
ดูเพิ่มเติมที่นี่
https://docs.angularjs.org/api/ng/service/$http

สามารถศึกษา เพิ่มเติมได้ที่
บทเรียน HTML
บทเรียน-html5
บทเรียน CSS
บทเรียน Javascript
บทเรียน jquery
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 73