Home > Article > Web Front-end > How to solve the node res.write garbled problem
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})".
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!