views:

162

answers:

2

Hi,

I'm writing my first little AJAX-enabled Joomla component. I'm using mootools. I got a xmlhttprequest to contact my Joomla component, and the component returns a response - just plain text echoed by php, like

echo 'Hello World!';

It's all working fine, except wireshark tells me that the response is prepended with \357\273\277\357\273\277 when it gets read by the javascript on the client side. This shows up as a little square before the response in an alert box that the script shows.

I don't explicitly set the encoding on the xmlhttprequest; mootools docs say that it defaults to UTF8.

What's the right way to handle this? Should I be setting the encoding on the request? Mime type? Should the javascript get rid of it? I'm not planning to have any characters requiring UTF8 in the response, so using plain old ascii would be ok for me too.

Thanks

A: 

A UTF-8 BOM is generally not recommended. Byte-order cannot be reversed in UTF-8 so it serves little purpose other than to just inform the consuming source that the following content is, indeed, UTF-8 encoded.

I'd strip it either on the Joomla end (preferred) or with javascript.

Also, for whatever reason, it looks like you have a double BOM there.

This related question might help as well.

Peter Bailey
A: 

I'm using Microsoft Expression Web 3, and even though it was set to not add a BOM for php files, there was indeed a BOM at the beginning of php files. I used a hex editor to remove the BOM, and now Expression doesn't add a BOM anymore while saving.

I don't know why there was 2 BOMs in the xmlhttprequest response, but now they're both gone.

Jimmy