显示提交的文本

时间:2013-04-12 11:55:34

标签: php ajax codeigniter

我正在textarea中写一些文字,并使用ajax调用显示它,所以当我输入一些文字并按Enter键换新行然后输入文字然后提交后我无法获得准确的文字输入 例如在textarea我就这样

Hi
helo
world

然后在提交我的文本后,像这样收到它

Hi helo world 

我输入后如何获取文字。 这是我的textarea代码

 <p>
     <textarea id="wall_post_comment" name="wall_post_comment></textarea>
 </p>
 <a href="javascript:void(0)" onclick="submit_wall();">Post</a>

这是我的功能

function submit_wall()
{
    var text=$('#wall_post_comment').val();
    $.post('<?php echo base_url()?>users/wall_post', { text:text },  
    function(data) {
                $('#wall_post_comment').val('');
                $(data).hide().insertAfter('#wall_post').slideDown('slow');
    }); 
}

这是我的模型代码,我将返回我的文本

function returnWall($text)
{        
    return '<div >

    &nbsp;'.$text.'
   </div>';
}   

更新

2 个答案:

答案 0 :(得分:3)

只需将nl2br添加到您的模型代码中

function returnWall($text)
{        
   return '<div >
   &nbsp;'.nl2br($text).'
   </div>';
 } 

答案 1 :(得分:1)

假设您的returnWall()功能有效,您可以使用nl2br功能将换行符转换为<br><br />

function returnWall($text)
{        
   return '<div>&nbsp;'.nl2br($text).'</div>';
}  
相关问题