使用Ajax将文本区附加到Cake PHP [英] Append Textarea with Cake PHP using Ajax

查看:172
本文介绍了使用Ajax将文本区附加到Cake PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速问题
是否有使用Cakephp附加textarea的方法

Quick questions Is there Way to Append a textarea using Cakephp

查看代码:

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

控制器代码:

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

}

上述代码提取信息但是替换整个文本文本区。
有一种方法,我可以只是附加textarea删除文本中的现有文本

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.

推荐答案

您可以尝试将AJAX请求的结果保存到隐藏字段,然后让它执行,

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.

AJAX助手允许您指定回调函数,所以像 这样的东西应该工作:

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()" )
 ); 
?>

然后在视图中的JavaScript

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>

注意:上面的JavaScript示例假设您使用的是JQuery, 不是。

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

这篇关于使用Ajax将文本区附加到Cake PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆