Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle newlines in JSON (AJAX) 2

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
I am using PHP on the server-side to pass database data back to Javascript (AJAX, but with JSON instead of XML), and sometimes I'll need to pass the same data back and forth a couple times (while various user feedback is requested to finalize it), but finally, it will go in the database as regular data and on the page as "innerHTML" content. But I'm having problems with newlines - of course if I put one in the JSON string as is, the eval() gives an "unterminated string literal" error, but the strange thing is that even if I change the newlines to "<br />" when constructing the JSON, eval() still gives the same error. Does Javascript really interpret "<br />" as a newline internally? If so, what should I use to represent newlines? I haven't even yet worried about how to get it back to the server-side once it's been transformed to something that Javascript likes - I figured I'd cross that bridge when I come to it - but if someone has been down this road and has a method for making a round-trip with the data, that's a bonus.
 
tsuji
Probably clearer if you just type '[ignore]forum1600[/ignore]' without the quotes which yields forum1600.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Tsuji's link was perfectly clear to me, and I immediately posted my question in that forum ( It's not as active a forum as this one, but I did receive a tip that helped me find my problem.

In fact, just for that, I'm going to give Tsuji-san a star. (I say "san" because I suspect he/she is Japanese, and that's how we address people here. [wavey2]) Arigatou!
 
Thanks Dan [smile]

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Wow, this is becoming quite a star-studded thread for one that didn't actually contain a technical discussion. [wink]

Actually I wasn't sure from John's hint where I was to type "forum1600" - I'm afraid to admit my ignorance, because it's probably obvious, but... So I didn't understand how that would be clearer than providing a link that goes to the forum.

I have discovered, though, that in some cases where there is a specialized forum that better fits a certain question, that doesn't mean the question will get answered faster or better there. In this case it worked out fine, but sometimes the specialized forums have such a small readership that no one replies. (For example, I recently posted something on the Windows forum and someone suggested the Antivirus forum, but it has been very quiet over there...[ponder]) The forums only work if people read them. But overall, Tek-tips has been great - definitely a lot of smart people reading!
 
Actually I wasn't sure from John's hint where I was to type "forum1600"

Actually, the hint was targeted at tsuji because he posted the forum's url. When you type the word forum, followed by the forum code (1600 for ajax, javascript is 216 for example) then the forum will auto-convert it to the forum name/description with a hyperlink straight to that forum. To find out which code corresponds to which forum, when visiting that forum's list of threads, there will be a link at the top of the page with the code listed.

So, if I type "forum1600" and "forum216" below (without the quotes) it produces this:

forum1600 and forum216


-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I have the urge to respond with the Japanese word "naruhodo" - loosely translated as, "Ah, that makes sense, now I see." [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top