我尝试res.render('mytemplate',数据),在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);
有什么想法吗?
答案 0 :(得分:1)
解决了它:
res.render(myTemplate, data,
function(err, rendered) {
// console.log(rendered);
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(rendered);
});
听听......
答案 1 :(得分:0)
这只是一个想法,但从它是抱怨的Safari的事实判断,可能是内容类型标题都是小写,而不是正确的Content-Type
?试试......
编辑:我看到你的其他答案,问题是200 OK ......