I was wondering what will happen if I run this code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MimeType Tester</title>
<meta charset="utf-8" />
<meta content="text/xml; charset=utf-8" http-equiv="content-type" />
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>
<body>
</body>
</html>
My content will be parsed as XML or HTML? Both? Other?
Also I have a JS code that sets mimetype twice:
req = new XMLHttpRequest();
req.overrideMimeType('text/xml');
req.overrideMimeType('text/html');
My content will be parsed as XML or HTML? Both? Other?
Is there a diffrent between both codes?
Is the result the same?
Taking the HTML first. Unless the server interprets the
meta http-equiv=content-typesetting and converts it to a real HTTP header (which HTML4 says is the purpose ofmeta http-equiv, but servers almost never do) then the HTTP content-type is not affected, and it is that, not the meta http-equiv setting (or the doctype) that determines whether the HTML or XML parser is invoked.So that normally means that the HTML parser will be invoked, but configuration or application code external to your question may cause the browser to process it differently. (As XML, or plain text, or binary data or something else)
As for the JS, I don’t know and haven’t tested it, but can think of no reason why the second overrideMimeType call wouldn’t replace the setting of the first call, and the request would go out with a content-type of
text/html. This seems to be the effect of the requirements of the spec here : http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-overridemimetype%28%29-method but it doesn’t explicitly cover this case.How the server interprets the mime type and content sent from the browser is entirely down to the code running on the server. It may take the mime type into account to select a parser, it may ignore it, or do something entirely contrary.