views:

123

answers:

1

Admit me describe my questions in situation-oriented way:

Assume Internet Explorer is still the dominating web browser (Firefox has document for binary processing):

The XMLHttpRequest.responseText or XMLHttpRequest.responseXML in Internet Explorer desire txt or xml/xhtml/html, but what about the server response the xmlHttprequest with MIME TYPE application/octet? Would the characters in the response string all be less than 256? (every character of that string < 256)? Thanks very much for a straight answer, I have no webserver environment, so I don't know how to test it out.

Because use of txt or xml have an issue of character set encoding, and I don't know how to process #[[[CDDATA node of one encoded xml (for example: UTF-8, ASCII, GB18030) with JavaScript, when I getNodeText, does the docObj return me byte or decoded char? If it was decoded char which according to the header indicated charSet in the httpresponse, it would be all wrong.

To avoid mess up with charSet, I would like the server to response octet data and force strings data to be encoded as UTF-8 but another charSet in the binary format.

If the response is octal, so I guess the browser would not try to decode the response "txt".

Does this weird? Or miss understanding the fundamental things?

EDIT: I believe the question is asking this: Can JavaScript safely process strings that aren't encoded in Unicode? What are the problems with trying to do so?

EDIT: no no no , I mean if http-header: content-type is "application/octet", would Internet Explorer try to decode it as (16 bits Unicode or Internet Explorer local setting charset) when I get XMLHttpRequestobj.responseText use JavaScript? Or it (Internet Explorer) just wrap every single byte of the response body as a JavaScript string, then every character in that string less than or equal 256 (character <= 256).

Am I talking Mars language? Sadly, if I were Marsian, I would come as tourist without fuzzy questions. However I am in a country which share at least one property with Mars: RED.

A: 

If I understand your question correctly, the short answer is: yes, every single byte will contain a value between 0 and 255 (unsigned, that is). That's just the nature of bytes, consisting of 8 bits.

But why do you want this? What binary data do you want to process using JavaScript?

Just FYI, read Mastering Ajax, Part 3: Advanced requests and responses in Ajax:

This allows you to determine […] if the server will try to return binary data instead of HTML, text, or XML (which are all three much easier to process in JavaScript than binary data).

(under Useful HEAD requests).

In case you wondered, I found this article with a simple Google search.

Marcel Korpel
hehe ,my question labeled: -2, seems not very useful for somebody,but at least useful for me. thank your so straight and so particular answer. i want use more admire words,but base on my vocabulary level,i don't wanna to act like gay,thanks again.
Johnny
because use txt or xml have a issue of character set encode, and i don't know how to process #[[[CDDATA node of one encoded xml(ex : utf-8,ascii,gb18030) with javascript, when i getNodeText, does the docObj return me byte or decoded char ? if it was decoded char which according to the header indicated charSet in the httpresponse , it would be all wrong.
Johnny
@Johnny: I suppose your question got downvoted because it's not clear. I understand that your vocabulary is not so good, but we really have to think what you're trying to ask. Regarding your second comment: you should update your question with this information. It would also be helpful if you provide relevant source code. In general, HTTP headers overrule encoding set inside a file. See http://www.w3.org/International/O-charset and http://www.w3.org/International/tutorials/tutorial-char-enc/
Marcel Korpel
to avoid mess up with charSet ,i would to like server response octect data and force strings data to be encoded as utf-8 but another charSet.if the response is octal, so i guess the browser would not try to decode the response "txt"does this weird? or miss understanding the fundamental things?
Johnny
thank Marcel Korpel, i do have practice of refine questions of articles.i 'll do it tomorrow.
Johnny