I have a project that saves user inputs from HTML form and get saved in MySQL db.
For example, I have this function
function funcGetRecordDetails(editID){
$('#hiddenID').val(editID);
var action = "get_record_teams";
$.ajax({
url : "teams_post.php",
type : 'post' ,
data : { editID : editID,
action: action } ,
success : function(data, status){
var edit_data = JSON.parse(data);
$('#mdl_update_team_order').val(edit_data.order_no);
$('#mdl_update_team_team').val(edit_data.team);
$('#mdl_update_team_names').val(edit_data.name);
}
});
}
In my case edit_data.name
will have line breaks. But mdl_update_team_names
textarea is NOT displaying the line breaks properly.
For example, the data in DB is saved as a\nb
and that is exactly how it will be shown in the textarea.
For testing purpose, I changed it to $('#mdl_update_team_names').val('a\nb');
and the textarea IS displaying line breaks properly which is
a
b
Any idea how to display the line breaks properly from the DB?
Edit 1
When I do this, it works
var edit_data = JSON.parse('{"id":41,"snow_inc":"XXX","order_no":0,"team":"44","name":"a\\nb","update_by":"XXX","update_date_time":"2021-09-08 14:12:01"}')
But when I do this, it doesnt work.
var edit_data = JSON.parse(data)
But the response I'm getting is the same, which is
{"id":41,"snow_inc":"XXX","order_no":0,"team":"44","name":"a\\nb","update_by":"XXX","update_date_time":"2021-09-08 14:12:01"}
Tried this as well var edit_data = JSON.parse(data.toString());
with the same results.
");` to replace `\n` by `
`. – KIKO Software Sep 09 '21 at 10:43