node.js、express.js - res.render 在 safari 中不起作用,将 html 源显示为纯文本
我尝试 res.render('mytemplate', data),在除 Safari(包括 iOS)之外的所有浏览器中都能正常工作,Safari 不会渲染并以纯文本显示 html,还有一些标题信息:
HTTP/1.1 success unknown
X-Powered-By: Express
content-type: text/html
Content-Length: 4489
Set-Cookie: connect.sid=pSY62z68tPe4TnQBLuhBPaVZ.Hd7o0jSkf%2F4AztPcwxhwoWgeqbIggMBrRfRHV3L7G0g; path=/; expires=Tue, 14 Feb 2012 05:27:49 GMT; httpOnly
Connection: keep-alive
<!doctype html>
<!--[if lt IE 7]>
<html class="no-js ie6 oldie" lang="en"><![endif]-->
...
</html>
这就是我进行渲染的方式:
res.setHeader('content-type', 'text/html');
res.render('myTemplate', data);
有什么想法吗?
I try to res.render('mytemplate', data), works fine in all browsers except Safari (incl. iOS), Safari does not render and shows html in plain text, also some header info:
HTTP/1.1 success unknown
X-Powered-By: Express
content-type: text/html
Content-Length: 4489
Set-Cookie: connect.sid=pSY62z68tPe4TnQBLuhBPaVZ.Hd7o0jSkf%2F4AztPcwxhwoWgeqbIggMBrRfRHV3L7G0g; path=/; expires=Tue, 14 Feb 2012 05:27:49 GMT; httpOnly
Connection: keep-alive
<!doctype html>
<!--[if lt IE 7]>
<html class="no-js ie6 oldie" lang="en"><![endif]-->
...
</html>
This is how I do the rendering:
res.setHeader('content-type', 'text/html');
res.render('myTemplate', data);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了:
感谢聆听...
solved it:
thx for listening ...
这只是一个想法,但从 Safari 抱怨的事实来看,是否是 content-type 标头全部是小写,而不是正确的
Content-Type
?尝试一下...编辑:我从你的其他答案中看到问题是 200 OK...
This is just a thought, but judging by the fact that it's Safari that is complaining, could it be that the content-type header is all lower case, and not the proper
Content-Type
? Try that...Edit: I see by your other answer that the problem was the 200 OK...