Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
Line break issue with textarea

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda