简体   繁体   中英

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 (requested 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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