line-ajax,javascript - Textarea linebreak using ajax - Stack Overflow

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(/
/gi, '\n');

$('.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(/\n/g, '
');

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

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值