Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is happening because:</p> <ol> <li><p>The correct action is not being called, because you have not set the <code>url</code> property of <a href="http://api.jquery.com/jQuery.ajax/"><code>jQuery.ajax()</code></a>. You should know that Yii's <code>CHtml::ajax</code> is built on top of jQuery's ajax. So you can add :</p> <pre><code>CHtml::ajax(array( ... 'url'=&gt;$this-&gt;createUrl('customer/delete', array('id' =&gt; $data-&gt;id,'ajax'=&gt;'delete')), ... )) </code></pre> <p>Also in the url i'm passing an ajax parameter so that the action knows that it's an ajax request explicitly.</p></li> <li><p>Then the controller action by default(i.e Gii generated CRUD) expects the request to be of post type, you can see this in the customer/delete action line:<code>if(Yii::app()-&gt;request-&gt;isPostRequest){...}</code>. So you have to send a POST request, again modify the ajax options:</p> <pre><code>CHtml::ajax(array( ... 'type'=&gt;'POST', 'url'=&gt;'',// copy from point 1 above ... )) </code></pre></li> <li><p>Alternatively you can also use <a href="http://www.yiiframework.com/doc/api/1.1/CHtml#ajaxLink-detail"><code>CHtml::ajaxLink()</code></a>.</p></li> <li><p>To update the CListView after deletion, call <code>$.fn.yiiListView.update("id_of_the_listview");</code>. Something like:</p> <pre><code>CHtml::ajax(array( ... 'type'=&gt;'POST', 'url'=&gt;'',// copy from point 1 above 'complete'=&gt;'js:function(jqXHR, textStatus){$.fn.yiiListView.update("mylistview");}' ... )) </code></pre></li> </ol>
 

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