nbhbdm | Don & # 39 ; t you know Baidu
kandi X-RAY | nbhbdm Summary
kandi X-RAY | nbhbdm Summary
Don't you know Baidu?
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of nbhbdm
nbhbdm Key Features
nbhbdm Examples and Code Snippets
Community Discussions
Trending Discussions on nbhbdm
QUESTION
I used Node.js and Express for the first time to make an API and I am having some issues.
I'm using Node.JS 13.11.0 and Express 4.17.1.
When I try to access 127.0.0.1:4008/api/nbhbdm and append parameters, I receive this error.
ANSWER
Answered 2020-Jul-11 at 12:57I have seen Error: Can't set headers after they are sent to the client, but I don't think I have tried to send multiple responses to the same request.
You have, you just didn't notice it.
The onreadystatechange event is triggered four times (1-4), one time for each change in the readyState.
Source: https://www.w3schools.com/js/js_ajax_http_response.asp
Every time onreadystatechange is triggered and the readyState isn't 4 or the status isn't 200, you try and send a response to the client with res.json(). Since you cannot send several responses to the same request, you get thrown an error.
You'd need your onreadystatechange callback to disregard any readystate that isn't 4, and then act depending on the status of the request:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nbhbdm
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page