…meie igapäevast IT’d anna meile igapäev…

2009-11-13

Headers in JavaScript: Firefox vs others

Problem with a JS-heavy web application. Administrators have some extra controls, which should be visible if server sends “seeall” header with a value “True” (don’t worry, the actual check about using those controls is on server-side, this is just for visibility). It works fine in Firefox, but fails completely in IE and Chrome.

Everything looks completely legit in other browsers. The header exists and has the value “True”… but the comparison still fails.

In the end I found the issue – it seems that Chrome and IE do not strip \r (carriage return) control symbol from the header value string. This can be illustrated with the following pseudocode:

if (data.getResponseHeader['seeall'] == 'True') alert("True in Firefox");

if (data.getResponseHeader['seeall'] == 'True\r') alert("True in non-Firefox");
 
The quick’n’dirty solution? Compare just first four symbols…

Create a free website or blog at WordPress.com.