Home  >  Article  >  Backend Development  >  AJAX的php 头部函数怎么用?

AJAX的php 头部函数怎么用?

WBOY
WBOYOriginal
2016-06-06 20:07:55941browse

<code>
    //这里两句话很重要,第一讲话告诉浏览器返回的数据是xml格式
    header("Content-Type: text/xml;charset=utf-8");
    //告诉浏览器不要缓存数据
    header("Cache-Control: no-cache");</code>

这俩是我学习资料的,我理解 head 就是修改 html 的 meta标签,但是第一个设置字符集能对起来,第二个对不起来,有规范吗

<code><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="expires" content="no-cache"></code>

回复内容:

<code>
    //这里两句话很重要,第一讲话告诉浏览器返回的数据是xml格式
    header("Content-Type: text/xml;charset=utf-8");
    //告诉浏览器不要缓存数据
    header("Cache-Control: no-cache");</code>

这俩是我学习资料的,我理解 head 就是修改 html 的 meta标签,但是第一个设置字符集能对起来,第二个对不起来,有规范吗

<code><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="expires" content="no-cache"></code>

这两个是完全不一样的东西。
PHP里面的header()控制的是http协议的header信息。里面包含cookie,referer,缓存设定,
meta数据是http内容的一部分,主要用于给扫描器/搜索蜘蛛/浏览器/辅助阅读设备等等机器做辅助判断的。

所以这俩怎么可能对应的上。

另外,http header声明的编码方式有更高的优先级,可以覆盖掉meta里面的声明

headerHTTP协议中的头,meta是提供给浏览器识别的一些信息,其中有部分名称或意义可能是相同,但两个东西完全是独立的。

应该是说,metahttp-equiv 具有 http 头的作用。
http 头里面Cache-Controlexpires 都是有的,都是用作缓存控制。
http://yuedu.baidu.com/ebook/478d1a62376baf1ffc4fad99
https://www.ietf.org/rfc/rfc2616.txt
AJAX的php 头部函数怎么用?

如果php的header解决了html的事那么还要html做什么

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn