weixin_33726313 2016-06-29 09:32 采纳率: 0%
浏览 162

使用Ajax的Textarea换行

I got a textarea for updating a description but when i save it using ajax it doesn't follow the spaces i made in the textarea.

$('#edit-desc').on('click', function () {
    var i = $('.edit-description'), 
    v = i.val();
    if ($(this).hasClass('edit-desc')) {
       $(this).text('UPDATE');
       item_val = $('#desc_item').html().replace(/<br>/gi, '
');
       $('.edit-description').show();
       $('.edit-description').val(item_val);
       $('#desc_item').hide();
       $('.edit-description').focus();
       console.log("you pressed the EDIT");
    } else {
       $(this).text('EDIT');
       item_val = $('.edit-description').val().replace(/
/g, '<br/>');
       item_id = $('#collection_item_id').val();
       $('.edit-description').hide();
       $('#desc_item').show();
       $('#desc_item').html(item_val);

       $.post('php/edit-item-description.php', {item_id: item_id,        item_val: item_val}, function(e){
           location.reload();
       });
    }
    $(this).toggleClass('edit-desc');
});

and on my edit-item-description php is

<?php
    session_start();
    include 'connect.php';
    include 'exec/functions.php';

    $edit['item_id'] = $_POST['item_id'];
    $edit['brand'] = nl2br($_POST['item_val']);

    if(editCollectionName($edit)){
        echo "success";
    }else{
        echo "something wrong";
    }
?>

When i typed: A B C D in the textarea, and save it. It shows ABCD instead of having spaces /
in it

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog