views:

24

answers:

2

I found the following code in one of the pages I have to maintain;

document.getElementById('dummy').innerHTML = httpRequest.responseText;
return document.getElementById('dummy').innerHTML;

expecting it to do nothing, I replaced it with

return httpRequest.responseText;

but then the script choked on the input. It turned out that there were \r characters at the end of the line, so apparently the code above was to clean up the newlines.

Is there a cleaner way to do so without having to place the text in a html dummy element?

+1  A: 

Use the string.replace function:

return httpRequest.responseText.replace(/\r/g, "");
Oded
A: 

Use \g to replace all \r characters or else replace will remove only one \r .

httpRequest.responseText.replace(/\r/g, '');

jack