views:

94

answers:

1

I've recently asked and had answered this question and it's stopped the issue of the string literal error, however it's now caused another problem

$(document).ready(function()
{

 $("#message-list .message").click(function()
    {
     var msg_id = 1;
     msg_id = $(this).attr('id').split('-')[1];
  $.ajax({
   type: "GET",
   url: "get_message.php",
   data: "id=" + msg_id,
   success: function(msg){

    var converter = new Attacklab.showdown.converter();
    json = eval("("+ msg +")");
    var copy = converter.makeHtml(json.copy);

    $("#message-details .subject").html(json.title);
       $("#message-details .importance").html(json.importance);
       $("#message-details .date").html(json.date);
       $("#message-details .message").html(copy);


   }
  });
    });


});

this is the jquery function that the string is parsed into (json.copy to be exact) and is where the problem occurs. On creating the json string as in my previous question we removed any \r as they were not parsing out and escaping \n with \n. However i now have the issue of the new lines printing \n on the screen and need a way within this function to unparse them without causing the unterminated string literal error again.

>_<

EDIT:

Message:

all\n\n \n\n advisers\n\n \n\n at\n\n newtown

json string for that coming in is :

{"title":"testing again","copy":"all\n\n\n\n\n\nadvisers\n\n\n\n\n\nat\n\n\nnewtown","importance":"read Now","date":"2009-09-22 13:12:22"}

+1  A: 

It's a quick and dirty hack, but it would be fast as well: why don't you just replace "\n" with "<br />"?

Phil.Wheeler
that very well may be a good idea lol... i'll give it a go
Neil Hickman
works fine.. thanks!
Neil Hickman