অঙ্গুলার জেএস এইচটিটিপি রিকুয়েস্ট AngularJS XMLHttpRequest . AngularJS XMLHttpRequest

অঙ্গুলার জেএস এইচটিটিপি রিকুয়েস্ট AngularJS XMLHttpRequest
মো: আসাদুজ্জামান (Md. Asaduzzaman)
ফ্রিল্যান্সার (ওয়েব ডিজাইনার এবং ডেভেলপার)

$http রিমোট সার্ভার থেকে তথ্য পড়ার জন্য একটি AngularJS সার্ভিস।

একটি JSON ফাইল পড়া (Reading a JSON File)

নিম্নলিখিত স্ট্যাটিক JSON ফাইল একটি ওয়েব সার্ভারে সংরক্ষণ করা হয়:

http://www.justetc.com/website/Customers_JSON.php
[
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico"
},
{
"Name" : "Ernst Handel",
"City" : "Graz",
"Country" : "Austria"
},
{
"Name" : "FISSA Fabrica Inter. Salchichas S.A.",
"City" : "Madrid",
"Country" : "Spain"
},
{
"Name" : "Galería del gastrónomo",
"City" : "Barcelona",
"Country" : "Spain"
},
{
"Name" : "Island Trading",
"City" : "Cowes",
"Country" : "UK"
},
{
"Name" : "Königlich Essen",
"City" : "Brandenburg",
"Country" : "Germany"
},
{
"Name" : "Laughing Bacchus Wine Cellars",
"City" : "Vancouver",
"Country" : "Canada"
},
{
"Name" : "Magazzini Alimentari Riuniti",
"City" : "Bergamo",
"Country" : "Italy"
},
{
"Name" : "North/South",
"City" : "London",
"Country" : "UK"
},
{
"Name" : "Paris spécialités",
"City" : "Paris",
"Country" : "France"
},
{
"Name" : "Rattlesnake Canyon Grocery",
"City" : "Albuquerque",
"Country" : "USA"
},
{
"Name" : "Simons bistro",
"City" : "København",
"Country" : "Denmark"
},
{
"Name" : "The Big Cheese",
"City" : "Portland",
"Country" : "USA"
},
{
"Name" : "Vaffeljernet",
"City" : "Århus",
"Country" : "Denmark"
},
{
"Name" : "Wolski Zajazd",
"City" : "Warszawa",
"Country" : "Poland"
}
]

AngularJS $http

AngularJS $http ওয়েব সার্ভার থেকে তথ্য রিড করার জন্য একটি কোর সার্ভিস।

$http.get (url) ফাংশনটি সার্ভার ডাটা রিড করার জন্য ব্যবহৃত হয়।

অঙ্গুলার জেএস উদাহরণ:
customersController">

<ul>
<li ng-repeat="x in names">
{{ x.Name + ', ' + x.Country }}
</li>
</ul>

</div>

<script>
function customersController($scope,$http) {
$http.get("http://www.justetc.com/website/Customers_JSON.php")
.success(function(response) {$scope.names = response;});
}
</script>

এপ্লিকেশন ব্যাখ্যা:

AngularJS এপ্লিকেশন ng-app দ্বারা ডিফাইন করা হয়। এপ্লিকেশনটি

ভিতরে রান করে।

ng-controller ডিরেক্টিভ কন্ট্রোলার অবজেক্ট এর নামকরণ করে।

customersController ফাংশন একটি আদর্শ জাভাস্ক্রিপ্ট অবজেক্ট কন্সট্রাক্টর।

AngularJS একটি $scope এবং $http অবজেক্ট এর সাথে customersController কে কল করবে।
$scope অ্যাপ্লিকেশন অবজেক্ট ( ভেরিয়েবল এবং ফাংশন এপ্লিকেশন এর স্বত্ত্বাধিকারী (Owner))।

$http একটি XMLHttpRequest অবজেক্ট এক্সটার্নাল ডাটা রিকুয়েস্ট এর জন্য।

$ http.get() স্ট্যাটিক JSON ডাটা করে http://www.justetc.com/website/Customers_JSON.php থেকে।

যদি সফল হয় (success), কন্ট্রোলার (names) প্রোপার্টি ক্রিয়েট করে স্কোপ এর মধ্যে, সার্ভার থেকে JSON ডাটা এর সাথে।
নোট: উপরের উল্লেখ্য কোড একটি ডাটাবেস থেকে তথ্য সংগ্রহ করার জন্যও ব্যবহার করা যেতে পারে.

AngularJS will invoke customersController with a $scope and $http object.

$scope is the application object (the owner of application variables and functions).

$http is an XMLHttpRequest object for requesting external data.

$http.get() reads static JSON data from http://www.justetc.com/website/Customers_JSON.php.

If success, the controller creates a property (names) in the scope, with JSON data from the server.

Note The code above can also be used to fetch data from a database.

Permanent link to this article: http://bangla.sitestree.com/%e0%a6%85%e0%a6%99%e0%a7%8d%e0%a6%97%e0%a7%81%e0%a6%b2%e0%a6%be%e0%a6%b0-%e0%a6%9c%e0%a7%87%e0%a6%8f%e0%a6%b8-%e0%a6%8f%e0%a6%87%e0%a6%9a%e0%a6%9f%e0%a6%bf%e0%a6%9f%e0%a6%bf%e0%a6%aa%e0%a6%bf/