So when I attempt the following two responses from nodejs the behavior is different in the browser specifically chrome. I have a file with just the following content SOMESTRING
var string = fs.readSync(filename,'ascii');
res.end(string);
VS.
res.end('SOMESTRING');
and on the front end I use jQuery and I do the following.
$.ajax({type: params.type,
url: 'ajaxrequest',
cache: false,
data: {"name":"value"},
dataType:'text',
error: function(jqXHR, textStatus, errorThrown) {
},
success: function(data, textStatus, jqXHR) {
if(data == 'SOMESTRING')
console.log('data == SOMESTRING');
}
});
No matter what the encoding is (utf8,etc) or trying string.toString() I can not get data == 'SOMESTRING' eventhough if I just res.end('SOMESTRING') the equality works just fine. And yes I am certain that there is no extra white spaces or return carriage.
Try console.log('[' + data + ']');
. I'll bet you'll find a newline in there.