为什么我们使用http请求来获取数据? [英] Why we use http request to get data?

查看:75
本文介绍了为什么我们使用http请求来获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的Que是为什么我们使用http请求来获取数据?

什么是http?请详细说明



我尝试了什么:



我搜索谷歌但没有得到它。

解决方案

正如您现在可能的角度是客户端框架,这意味着它在用户的浏览器中运行。因此,将复杂的计算留给用户的计算能力并不是最好的主意。此外,您可能需要访问存储在远程服务器上某些持久存储中的数据。

因此,核心思想是将数据存储和复杂计算留给远程服务器,而angular只处理演示文稿您的数据。

这就是为什么你需要一种角度与远程服务器通信的方法。你为此使用

 


http



服务器的自然方式是提供一些REST您的角度应用程序查询数据的API如下所示

 


http({
method:' GET'
url:' < span class =code-string> / yourApiEndpoint'
})。then( function successCallback(response){
< span class =code-comment> // 此回调将异步调用
/ / 当响应可用时
}, function errorCallback(response){如果发生错误,
// 异步调用
// 或服务器返回错误状态的响应。
});


Hi guys
My Que is that why we use http request to get data in angular??
whats that http?please explain in detail

What I have tried:

I search google but did not get it .

解决方案

As you might now angular is a client-side framework which means it operates in user's browser. So it's not the best idea to leave complex computations to user's computational capability. Also, you might need access to data stored in some persistent storage on a remote server.
So the core idea is that you leave data storage and complex computation to a remote server, whereas angular just handles the presentation of your data.
That's why you need a way for angular to communicate with a remote server. And you use


http

for this.
Natural way for server is to provide some REST API wich your angular app queries for data as following


http({ method: 'GET', url: '/yourApiEndpoint' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. });


这篇关于为什么我们使用http请求来获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆