Angular 4单个API请求多次运行 [英] Angular 4 single API request running multiple times

查看:176
本文介绍了Angular 4单个API请求多次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到有关Angular 4 App的问题。我创建了一个应用程序,其中的数据来自第三方API。我遇到的问题是我的API调用了多次,但是我只发送了一次请求。

I am having issue regarding Angular 4 App. I have created an app in which data is getting from third party APIs. The issue I am getting is my APIs are calling for multiple times but I sent request only once.

经过一些R& DI发现浏览器正在使用OPTION方法运行航班请求,但检查所有API后,我发现它们运行了多次,但航班请求除外。像fir一个API一样,我只请求一次API,并且它运行4次,选择2次,GET请求2次。我检查我的代码,只有一次请求在运行。

After some R&D I found browser is running flight request with OPTION method but after checking all APIs I found they are running for multiple times except flight request. Like fir an API I am requesting API once and it is running for 4 times 2 times for option and 2 times for GET request.I check my code and only one time request is running.

我完全理解并同意航班要求。

I totally understand and agree with flight request.

我分析了本地的所有通话,发现的是:
1.全部GET调用具有相应的OPTIONS调用,按照某些术语,这不是问题
2。但是,有多个调用针对这些调用:

I analyzed all the calls on my local and here is the finding: 1. all GET calls have corresponding OPTIONS call, which as per some artcle is not a problem 2. However, there are multiple calls for these:

http://localhost:3005/tasks?taskID=1713&singular=1 = 4 Get call, 2 OPTIONS call  - why?
http://localhost:3003/resources/30/configs = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/configs = 2 GET cal, 1 OPTIONS call - why?
http://localhost:3003/resources/30/settings = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/settings = 2 GET call, 1 OPTIONS call - why?

这些是GET多次的唯一调用。对于所有其他呼叫,/ environments,/ settings,/ admin,/ currentevent,/ currentshift .. get呼叫只进行一次。

These are the only calls where GET is multiple times. For all other calls, /environments, /settings, /admin,/currentevent,/currentshift.. get call is going only once.

return this.http.get(this.environment.SFDCServiceHost + 'getCurrentEvent?resourceId=' + id + '&singular=1', {headers: this._helperService.setRequestHeader(id)});

推荐答案

您的代码可能存在问题。浏览器没有添加运行请求,除了航班请求。要检查这一点,您首先要检查该函数调用了多少次。我对此非常有把握,因为我遇到了同样的问题。

There May be some issue with your code. Browser doesn't add run any extra request except flight request. To check this you first check how many time that function is calling. I am very sure about this because I had the same issue.

这篇关于Angular 4单个API请求多次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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