How to solve the node res.write garbled problem

藏色散人
Release: 2021-12-10 11:36:58
Original
1397 people have browsed it

Node res.write garbled solution: 1. Set the header information to "Content-Type':'text/plain; charset=utf-8"; 2. Set the code to "res.write( JSON.stringify({msg:data})".

How to solve the node res.write garbled problem

The operating environment of this article: Windows 7 system, nodejs version 10.16.2, Dell G3 computer.

How to solve the problem of garbled characters in node res.write?

About the problem of nodejs res.write returning Chinese garbled characters

Need to add header information:

'Content-Type': 'text/plain; charset=utf-8'
Copy after login

As follows:

res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'}); res.write(JSON.stringify({msg:data}),'utf8');
Copy after login

Recommended learning: "node.js video tutorial"

The above is the detailed content of How to solve the node res.write garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!