Append Textarea with Cake PHP using Ajax

一曲冷凌霜 提交于 2020-01-06 14:16:21

问题


Quick questions Is there Way to Append a textarea using Cakephp

view code:

<?php echo $ajax->link(   
     $qnote['Qnote']['subject'],
     array(
         'controller' => 'qnotes',
         'action' => 'view', $qnote['Qnote']['id']
 ),
     array( 'update' => 'Textarea_id')
 ); 
?>

controller Code:

    function view($id = null) {  
    $this->Qnote->id = $id;
    $this->set('qnote', $this->Qnote->read());

}

the above code Pulls the information But Replaces the entire Text in the textarea. Is there a way I can just append the textarea with out removing the existing text in the textarea

if possible can somebody point me in the right direction please.


回答1:


You can try saving the result of your AJAX request to a hidden field and then having it execute and on page javascript function to simply slap the values from the hidden field to the visible text area.

The AJAX helper lets your specify callback functions, so something like this should work:

<?php echo $ajax->link(   
     $qnote['Qnote']['subject'],
     array(
         'controller' => 'qnotes',
         'action' => 'view', $qnote['Qnote']['id']
 ),
     array( 'update' => 'Textarea_id_hidden', "complete" => "concat_fields()" )
 ); 
?>

and then the JavaScript in the View

<script type="text/javascript">
  function concat_fields() {
    $('#Textarea_id').val( $('#Textarea_id').val() . $('#Textarea_id_hidden').val() );
  }
</script>

Note: My JavaScript example above assumes you're using JQuery, changes will need to be made if you're not.



来源:https://stackoverflow.com/questions/5876684/append-textarea-with-cake-php-using-ajax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!