简体   繁体   English

Express JS,第二次对同一路径的GET请求始终处于待处理状态

[英]Express js, GET request to the same route for the second time always pending

I am developing an express application in which I need to render a landing page for '/' route. 我正在开发一个快速应用程序,其中需要呈现“ /”路线的登录页面。 This page has a text box and a button. 此页面有一个文本框和一个按钮。 When user adds text to textbox and hits submit button I need to make request to same url but with text added as its query parameter. 当用户将文本添加到文本框并单击“提交”按钮时,我需要向相同的url发出请求,但添加文本作为其查询参数。 This request will render a new page whose contents depend upon query text. 该请求将呈现一个新页面,其内容取决于查询文本。

Now what is happening is when user enters text into textbox and presses button, form makes GET request and route looks something like http://localhost:3000/?q=abc . 现在发生的是,当用户在文本框中输入文本并按下按钮时,表单使GET请求和路由看起来像http://localhost:3000/?q=abc I can see this request as pending in network tab of chrome developer tools but this request never reaches server. 我可以在chrome开发人员工具的“网络”标签中看到此请求处于待处理状态,但此请求从未到达服务器。 I cannot see any request for /?q=abc in server console. 我在服务器控制台中看不到对/?q=abc任何请求。

If I restart server and then open http://localhost:3000/?q=abc , proper contents get loaded in browser. 如果我重新启动服务器,然后打开http://localhost:3000/?q=abc ,则会在浏览器中加载正确的内容。 But if I change url back to http://localhost:3000 , I can see pending request in network tab and this request never reaches server. 但是,如果我将url更改回http://localhost:3000 ,则可以在“网络”选项卡中看到待处理的请求,并且此请求永远不会到达服务器。

My code looks something like: 我的代码如下所示:

app.get('/', function(req, res, next) {
  if(req.query.q) 
    res.render('results.ejs');
  else
    res.render('landing.ejs')
});

Any idea why no call to server is being made? 知道为什么不对服务器进行呼叫吗? I have spent whole day trying to figure out reason for this behavior. 我花了整整一天的时间来找出这种现象的原因。 Any help will be greatly appreciated. 任何帮助将不胜感激。

Have you tried inserting temporary middleware to see where exactly the request gets stuck in your middleware/route chain? 您是否尝试过插入临时中间件以查看请求在中间件/路由链中的确切位置? It sounds like there is a middleware somewhere that is not calling next() in some situation. 听起来有些地方在某些情况next()没有调用next()的中间件。

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

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