I have always been trying to avoid using most of the HTTP protocol's properties for the sake of fear of the unknown.(为了害怕未知,我一直试图避免使用大多数HTTP协议的属性。)
However, I said to myself that I'm going to face fear today and start using headers purposefully.(但是,我告诉自己今天我将面临恐惧并开始有目的地使用标题。)
I have been trying to send json
data to the browser and use it right away.(我一直在尝试将json
数据发送到浏览器并立即使用它。) For example, if I have an Ajax handler function on ready state 4 which looks like so:(例如,如果我在就绪状态4上有一个Ajax处理函数,它看起来像这样:)
function ajaxHandler(response){
alert(response.text);
}
And I have set the content-type header in my PHP code:(我在PHP代码中设置了content-type标头:)
header('Content-Type: application/json');
echo json_encode(array('text' => 'omrele'));
Why can't I directly access the property from the handler function, when the browser is clearly told that the incoming data is application/json
?(为什么我不能直接从处理函数访问属性,当浏览器被明确告知传入的数据是application/json
?)
ask by php_nub_qq translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…