2014-03-29 36 views
-1

我使用Yii框架,但如果我没有错,我认为这是对myjquery非法串偏移“名称”

我呈现的帖子

<?php 
/* @var $this PostController */ 
/* @var $data Post */ 
?> 

-- Get Post Subject 

    <b> <?php echo CHtml::encode(Contest::model()->getAttributeLabel('subject')); ?>:</b> 
    <?= CHtml::encode($data['subject']); ?> 

-- Place to get the controller/action from js script 

    <div id="dataComment<?php echo $data['id']; ?>" data-url="<?php echo Yii::app()->createUrl('post/ajax', array('post_id' => $data['id'])); ?>"></div> 

-- Button Link -- error when I click on the following button 

**-- localhost/blog/index.php/post/ajax?post_id=16 -- Illegal string offset 'name'** 


    <p><input type ="button" id="comment<?php echo $data['id']; ?>" 
    value="<?php echo ($comment_exist == NULL) ? 'Comment' : 'Cancel my Comment'; ?>"></p> 

列表相关 - jQuery脚本 --on文件准备

$('[id^="comment"]').click(function(e) { 

      var $thisClicked = $(this); 
      var parameter = $thisClicked.attr('id'); 
      parameter = parameter.replace('comment',''); 

      $.ajax({ 
       'url' : $('#dataComment' + parameter).data('url'), 
       'type' : 'POST', 
       'update': '.form', 
      });      

      $thisClicked.parent().next('.form').fadeIn(1500).slideDown(1300); 

     }); 

- 中邮控制器阿贾克斯行动

public function actionAjax($post_id){ 

    $model = new Comment; 

    $this->renderPartial('_formComment',array(
      'model'=>$model, 
      'post_id'=>$post_id, 

     )); 
} 

- _formComment.php

<div class="form" style="display:none"> 

     <?php $form=$this->beginWidget('CActiveForm', array( 
      'id'=>'comment-form', 
      'enableAjaxValidation'=>true, 
      'enableClientValidation'=>true, 
      'focus'=>array($model,'comment'),    
      )); 
     ?> 

     <div class="row"> 
      <?php echo $form->labelEx($model,'comment'); ?> 
      <?php echo $form->textField($model,'comment',array('size'=>60,'maxlength'=>140)); ?> 
      <?php echo $form->error($model,'comment'); ?> 
     </div> 

     <?php echo $form->hiddenField($model,'post_id',$post_id); ?> 


     <div class="row buttons"> 

      <?php 
        echo CHtml::ajaxButton('ajaxButton', 

        array(
        'type' => 'POST', 
        'success'=>'js:function(string){ alert(string); }'), 
        array('class'=>'someCssClass',)); 

        ?> 


      <p><input type ="button" id = "cancelComment" value="Cancel"></p> 
      <p><input type ="button" id = "deleteComment" value="Delete"></p> 
     </div> 

     <?php $this->endWidget(); ?> 
    </div> 

预先感谢您的帮助

+0

$就没有按”没有“更新”设置:http://api.jquery.com/jQuery.ajax/ –

+0

可能的重复[非法字符串偏移警告PHP](http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php) – CBroe

回答

0

更换你的隐藏字段

<?php echo $form->hiddenField($model,'post_id',$post_id); ?> 

<?php $form->hiddenField($model,'post_id',$post_id); ?> 
+0

伟大的,它的工作原理! – trinocle