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条回答 默认 最新

    报告相同问题?