I have always been trying to avoid using most of the HTTP protocol's properties for the sake of fear of the unknown.
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. For example, if I have an Ajax handler function on ready state 4 which looks like so:
function ajaxHandler(response){
alert(response.text);
}
And I have set the content-type header in my PHP code:
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
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…