Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda