csdnceshi62 2013-05-26 15:12 采纳率: 0%
浏览 45

jQuery追加+ PHP

I'm using Yii framework and I want call a PHP function and return a value.

This value has to be appended to a div. I try a lot of things but nothing works. This is more far that I get:

echo CHtml::ajaxSubmitButton('add one more',
    CController::createUrl('cadTabelapreco/UpdateFilho'),
array('type'=>'POST',
      'data'=>array('item'=>'CadTabelaprecoi',
                    'i'=>$i,            
      'complete' => 'function(){
            $("#data").append($(this).html()); 
      }',         
));

I also try this:

array('type'=>'POST',
      'data'=>array('item'=>'CadTabelaprecoi',
                    'i'=>$i,
                    'form'=>$form),            
      'complete' => 'function(ret){
            $("#data").append().val(ret); 
      }',         
));

The thing is, if I debug it with Firebug, I see the response and its right, but I can't append the value to the div. How to do that?

  • 写回答

2条回答 默认 最新

  • Memor.の 2013-05-27 06:45
    关注
    echo CHtml::ajaxSubmitButton('add one more',
        CController::createUrl('cadTabelapreco/UpdateFilho'),
    array('type'=>'POST',
          'data'=>array('item'=>'CadTabelaprecoi',
                        'i'=>$i,            
          'success' => 'function(data){//pass data to success function
          $("#data").empty();//clear div cause if without you'll stack data in your div      
          $("#data").append(data);//append your url return 
          }',         
    ));
    

    In your Controller :

    public function actionUpdateFilho{
    /**
    * Do what you need here
    */
    echo $result;//form variable string with result wich you want to output(in HTml format wich you need) 
    }
    

    It's working great for me. Hope this was helpfull.

    评论

报告相同问题?