Home  >  Article  >  Web Front-end  >  How to solve the node res.write garbled problem

How to solve the node res.write garbled problem

藏色散人
藏色散人Original
2021-12-10 11:36:581446browse

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'

As follows:

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

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!

Statement:
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