我有一個前端腳本,它從 HTML 按鈕中獲取一個值并將其傳遞給后端。它作業得很好,除了如果重復單擊按鈕以向后端發送一堆 POST 請求,則只有大約七八次通過,其余的在瀏覽器的元素檢查中顯示為待處理。
這是代碼的問題,還是可以預期這是網路中的某種埠過濾機制?
前端:
async function submitCity(){
let x = document.getElementById("wg_input").value;
console.log("Successfully captured city name:", x);
let toWeather = JSON.stringify({city: x});
console.log("Input data successfully converted to JSON string:", toWeather);
const options = {
method: 'POST',
mode: 'cors',
headers: {'Content-Type': 'application/json'},
body: toWeather
}
fetch('http://localhost:3000', options)
.then(res => console.log(res))
.catch(error => console.log(error))
}
服務器.js:
// Dependencies
const express = require('express');
const bp = require("body-parser");
const request = require("request");
const jimp = require('jimp');
const cors = require('cors');
const wgServer = express();
const port = 3000;
// Dotenv package
require("dotenv").config();
// OpenWeatherMap API_KEY
const apiKey = `${process.env.API_KEY}`;
// Basic server initialization
wgServer.use(cors())
wgServer.use(bp.json())
wgServer.use(bp.urlencoded({ extended: true }))
wgServer.listen(port, function() {
console.log(`Example app listening on port ${port}!`)
});
wgServer.post('/', async function (req, res) {
res.set('Content-Type', 'text/plain');
console.log(req.body);
let preclean = req.body;
console.log(preclean);
//const data = await req.body;
// let jsonData = JSON.stringify(req.body);
// res.status(201);
//res.json();
});
uj5u.com熱心網友回復:
這是瀏覽器將這些請求排隊,直到前一個請求完成。
瀏覽器對它們將發送到同一主機的同時請求的數量有限制。一旦達到該限制,他們就會將后續請求排隊,直到先前的請求之一完成,此時他們將發送佇列中的下一個請求。
這與網路中的過濾無關。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/448442.html
標籤:javascript 节点.js 休息 表示 联网
上一篇:Res.Render正在停止
