Note that there are some explanatory texts on larger screens.

plurals
  1. POYii- Ajax value not getting fired into controller
    primarykey
    data
    text
    <p>I'm new to Yii framework and Ajax. So now I'm using a <strong><code>ext.combobox.EJuiComboBox</code></strong> for creating a dropdownlist. Below is the code I'm using to create the dropdownlist in the view file : </p> <pre><code>&lt;?php $this-&gt;widget('ext.combobox.EJuiComboBox', array( 'model' =&gt; $model, 'attribute' =&gt; 'company_id', // data to populate the select. Must be an array. //'data' =&gt; $model-&gt;getAllModels(), 'data' =&gt; CHtml::listData(Company::model()-&gt;findAll(), 'id', 'name'), // options passed to plugin // Options passed to the text input 'options' =&gt; array( // JS code to execute on 'select' event, the selected item is // available through the 'item' variable. 'onSelect' =&gt; CHtml::ajax(array( 'type'=&gt;'POST', 'url'=&gt;CController::createAbsoluteUrl('bill/getProjects'), 'update'=&gt;'#'.CHtml::activeId($model,'project_id'), 'beforeSend' =&gt; 'function(){ $("#page").addClass("loading");}', 'complete' =&gt; 'function(){ $("#page").removeClass("loading"); $("#' . CHtml::activeId($model,'project_id') . '").trigger("change"); }', 'success'=&gt;"function(){ alert('ok');}" )), // JS code to be executed on 'change' event, the input is available // through the '$(this)' variable. 'allowText' =&gt; false, ), // Options passed to the text input 'htmlOptions' =&gt; array('style'=&gt;'width:70px' ) )); ?&gt; </code></pre> <p>Now, the ajax gets fired to controller, but the value of project_id is still 0. Now in the controller I have the following function. The alert box gets executed.</p> <pre><code>public function actionGetProjects() { $data=Project::model()-&gt;findAll('company_id=:company_id', array(':company_id'=&gt;(int) $_POST['Bill']['company_id'])); $data=CHtml::listData($data,'id','name'); foreach($data as $value=&gt;$name) { echo CHtml::tag('option', array('value'=&gt;$value),CHtml::encode($name),true); } } </code></pre> <p>In the logs generated I can see though I selected the company_id from values, the comapny_id says the value is 0. How can I debug this?</p> <pre><code>SELECT * FROM `project` `t` WHERE company_id=0 </code></pre> <p><strong>Edit</strong> Below is the look of view page <img src="https://i.stack.imgur.com/jNh95.png" alt="enter image description here"> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload