简体   繁体   English

具有不同参数的Axios GET请求将被丢弃

[英]Axios GET requests with different parameters are discarded

I've got a React application launching GET requests using Axios. 我有一个React应用程序使用Axios启动GET请求。 For some reason, when there are requests with different parameters, only the requests with one type of parameters are coursed with any trace in the chrome dev tools. 出于某种原因,当存在带有不同参数的请求时,只有带有一种类型的参数的请求才能在chrome dev工具中进行任何跟踪。 I've checked both console and network tab and there are no request. 我已经检查了“控制台”和“网络”选项卡,没有任何请求。

The application shows a map where I load data by tile, so my requests look like this: 该应用程序显示了一个地图,其中我按图块加载数据,因此我的请求如下所示:

http://SERVER_IP:1002/data/tile/6/15/39?param1=8&param2=paramValue1
http://SERVER_IP:1002/data/tile/6/15/40?param1=8&param2=paramValue1
http://SERVER_IP:1002/data/tile/6/15/41?param1=8&param2=paramValue1

http://SERVER_IP:1002/data/tile/6/15/39?param1=8&param2=paramValue2
http://SERVER_IP:1002/data/tile/6/15/40?param1=8&param2=paramValue2
http://SERVER_IP:1002/data/tile/6/15/41?param1=8&param2=paramValue2

This is my code: 这是我的代码:

return axios.get(
    serviceURL,
    {
      cancelToken: source.token,
      timeout: 20000,
      params: {
        param1,
        param2,
      },
    })
    .then(resolveRequest())
    .catch(handleErrors());

When the app launch requests with paramValue1 or paramValue2, they are coursed properly but when I have requests with both param values paramValue1 requests are not course without leaving any trace. 当应用程序启动带有paramValue1或paramValue2的请求时,它们会正确处理,但是当我同时具有两个param值的请求时,paramValue1请求就不会留下任何痕迹。 Any ideas? 有任何想法吗?

Note 1: My serving layer currently uses HTTP/1.1. 注意1:我的服务层目前使用HTTP / 1.1。

Note 2: For those not familiarized with tiles is just a way to divide a map in square regions making easy to load data by chunks. 注意2:对于不熟悉图块的用户来说,这只是将地图划分为正方形区域的一种方法,可以轻松地按块加载数据。

The problem was a mistake managing axios tokens. 问题是管理axios令牌时出错。 I store tokens of ongoing requests in a map. 我将正在进行的请求的令牌存储在地图中。 I forgot to update the map key with the new parameter added. 我忘记使用添加的新参数来更新地图键。 Having a unique identifier for every request solves the problem. 每个请求都有唯一的标识符可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM