php line break from ajax call not working

lharrispv
lharrispv used Ask the Experts™
on
so if I put the following syntax into my php page when I load the page it works like a charm.

<textarea style="height:200px; width:650px; name="requestbody" id="requestbody"><?php
if ($_SESSION['page'] == "2"){
foreach ($_SESSION['body'] as $key => $value){
      
echo $key . ' = ' . $value . "\n";

}
}

?>
</textarea>

If however, add a button that calls a js function to run an ajax call against a php with the same code in it then I lose the line break when set the value of the textarea to the response.

Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Does your server use a Windows or Linux based operating system ?

Try using PHP_EOL instead of "\n";

Like this:

echo $key . ' = ' . $value . PHP_EOL;

Author

Commented:
nope.. didn't work.... by the by... if I use <br/>, <p/>, <p></p> or I try to use nl2br I get an unkonwn runtime error.
echo htmlentities($key) . ' = ' . htmlentities($value) . PHP_EOL;
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
nope... and I am using xamp on a win xp to simulate a LAMP environment for dev purposes

Commented:
What are you using to execute the AJAX call? Are you using any major frameworks like jQuery? Those usually handle all the small details like line breaks and such...

Author

Commented:
no I am not... just as standard call..

here is some more info I just figured out... it works correctly in FF... breaking in IE7 and IE8

Commented:
I'd suggest just trying out one of those frameworks. They make life a lot easier when it comes to cross-browser functionality and easy AJAX calls.
ok problem solved.  I had to use .value instead of .innerHTML in my JS.

Thanx for your ideas guys!

Commented:
Don't delete the question. Accept your own solution as the answer so others can benefit.

Author

Commented:
if I do that then it will give me the points and I can't give myself points.  That is not right.

Commented:
No, it will not give you points. It will refund the points, but it will mark your answer as the solution so people can still see it.

If EE allowed members to simply ask questions and answer them right away and get all the points, everyone would be out of control. :)

Author

Commented:
ok I will do it then.  Thanx again for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial