简体   繁体   English

Ajax,内容类型标头和python

[英]Ajax, content-type header and python

When using python for web as opposed to PHP, you have to manually write this header: Content-type:text/html . 当将python用于Web而不是PHP时,必须手动编写以下标头: Content-type:text/html

If I want to change the inner HTML of an element with ajax, should my python script (requested by ajax) output the above header or just plain HTML as a response? 如果我想使用ajax更改元素的内部HTML,我的python脚本(由ajax请求)应该输出上述标头,还是仅输出纯HTML作为响应?

Every HTTP Response must include a Content-Type header. 每个HTTP响应必须包含一个Content-Type标头。 PHP happens to insert one by default. PHP碰巧默认会插入一个。 Whatever Python library you are using apparently doesn't. 无论您使用哪种Python库,显然都不会。 Therefore you need to provide one explicitly. 因此,您需要明确提供一个。

This leaves the question as "Should a fragment of HTML be served as text/html?" 剩下的问题是“是否应将HTML片段用作text / html?”

The RFC says: RFC说:

The text/html media type is now defined by W3C Recommendations; W3C建议书现在定义了text / html媒体类型; the latest published version is [HTML401]. 最新发布的版本是[HTML401]。 In addition, [XHTML1] defines a profile of use of XHTML which is compatible with HTML 4.01 and which may also be labeled as text/html. 另外,[XHTML1]定义了XHTML的使用配置文件,该配置文件与HTML 4.01兼容并且也可以标记为text / html。

These specifications do not define HTML fragments, so you should probably use something like: 这些规范未定义HTML片段,因此您可能应使用类似以下内容的代码:

Content-Type: x-text/html-fragment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM