Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Possible To Create Ajaxbutton In Controller And Send To Browser?

$
0
0
I can't seem to figure out what I'm doing wrong. I have a CGridView set up so that when I select row a call is made via Ajax to the actionEnrollment method of my controller (see code below). The result of this method is then used to populate a div on my webpage (e.g. document.getElementById("div-box-enrollment").innerHTML = response; ).

The problem is that the AjaxButton that is being sent from actionEnrollment is not making the calls back to the server. But if I take the same exact code and put it on my webpage it does make the call back to the server.

So I guess my question is: Can I send Ajax buttons like this from the server to the client? And if so what else do I need to do?

Thanks.

	public function actionEnrollment($orderid){
		$model=Order::model()->findByPk($orderid);		
		$enrollment=Enrollment::model()->findAllBySql('select * from enrollment where order_id = '.$orderid);
		
		echo '<div class="row">';
			echo '<center>';
			echo CHtml::label('Enrollments','',array('style'=>'text-align:center; font-weight:bold; color:#81A720; font-size:15px;'));
			echo '</center>';
		echo '</div>';

		echo '<div class="row"><center>';  
			echo CHtml::label('Total Fee: $'.$this->netAmount($model),'',array('style'=>'text-align:center; font-weight:bold; color:#81A720; font-size:15px;'));
		echo '</center></div><br>';
		
		$enroll_count=count($enrollment);
		$ctr=1;
		
		foreach($enrollment as $enroll){
			echo '<div class="row">';
				echo CHtml::label($ctr.'. '.$enroll->first_name.' '.$enroll->last_name,'',array('style'=>'color:#81A720; font-size:12px;'));
			echo '</div>';
			
			echo '<div class="row">';
				echo CHtml::label($enroll->school_name,'',array('style'=>'color:#6F6566; font-weight:bold; font-size:12px'));
			echo '</div>';
			
			echo '<div class="row">';
				echo CHtml::label($enroll->name,'',array('style'=>'color:#6F6566; font-weight:bold; font-size:12px'));
			echo '</div>';
			
			echo '<div class="row">';
				echo CHtml::label('Every '.$enroll->week_day.':','',array('style'=>'color:#6F6566; font-size:12px'));
			echo '</div>';
			
			echo '<div class="row">';
				echo CHtml::label($enroll->schedule,'',array('style'=>'color:#6F6566; font-size:12px'));
			echo '</div>';
				
			echo '<div class="row">';
				echo CHtml::label($enroll->beg_date.' to '.$enroll->end_date,'',array('style'=>'color:#6F6566; font-size:12px'));
			echo '</div>';
									
			echo '<div class="row">';
				echo CHtml::label($enroll->session_number.' sessions','',array('style'=>'color:#6F6566; font-size:12px'));
			echo '</div>';
			
			echo '<div class="row">';
				echo CHtml::label('Fee: $'.$enroll->total_cost,'',array('style'=>'color:#6F6566; font-weight:bold; font-size:12px'));
			echo '</div>';
						
			if($enroll->status === 'cancelled'){
				echo '<div class="row">';
					echo CHtml::label('Status: cancelled','',array('style'=>'color:#6F6566; font-weight:bold; font-size:12px'));
				echo '</div>';
			}else{
				echo '<div class="row"><center>';

					echo CHtml::ajaxButton('Cancel with Refund',
							array('orders/refund'),
							array(
								'dataType'=>'json',
								'type'=>'GET',
								'data'=>$model->order_id,
								'success'=>'function(data){                                             
                                              alert(data);
                                        }', 
								'failure'=>'function(data){                                             
                                              alert(data);
                                        }', 	
							));													
				echo '</center></div>';
					
				echo '<div class="row"><center>';
					echo CHtml::ajaxButton('Cancel without Refund',array('order/norefundcancel'));
				echo '</center></div>';
			}
				
			echo '<br> <br>';
			$ctr++;
		}
		
		echo '<div class="row">';
		echo '</div>';
	}

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>