开发者

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.

If I want to change the inner HTML of an element with ajax, should my python script (requ开发者_StackOverflow中文版ested by ajax) output the above header or just plain HTML as a response?


Every HTTP Response must include a Content-Type header. PHP happens to insert one by default. Whatever Python library you are using apparently doesn't. Therefore you need to provide one explicitly.

This leaves the question as "Should a fragment of HTML be served as text/html?"

The RFC says:

The text/html media type is now defined by W3C Recommendations; the latest published version is [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.

These specifications do not define HTML fragments, so you should probably use something like:

Content-Type: x-text/html-fragment
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜