[Solved] Problems With Ajaxlink In Cjuidialog

I have a CJuiDialog that displays some data, inside the content of the dialog I want to provide the user with a link to show some more related data (this new data will be shown in the same dialog replacing the previous).

The problems I am experiencing are:

  1. The action function (actionShowCategory) is being executed correctly but the array $_POST is empty

  2. After actionShowCategory is executed, ajaxLink’s ‘success’ function is not executed.

If I place the ajaxLink in the view page instead of the dialog’s content this works perfectly, but I need it to work inside the dialog.

Here is my code:

<?php echo CHtml::ajaxLink(

		"Show all items of this category",

		Yii::app()->createUrl( $this->getId() . '/showCategory' ),

		array( // ajax options

			'type' => 'POST',

			'data' => array('val1' => '1'),


				// Once showCategory has been executed the content result is injected here into the dialog

				// and then the dialog is opened

				$('#detailsDialog').html(content); return false;



		array( //htmlOptions

			'href' => Yii::app()->createUrl($this->getId() . '/showCategory'),

			//'class' => $class




Probably this topic is related but I don’t want to do a big workaround.

ajaxSubmitButton inside CJuiDialog not sending POST vars

Has anyone run into this issue?

Any help will be greatly appreciated!


[size=2]I don’t know if this will help (not seeing your entire view code), but I had a problem today with no POST data going to my controller from a CHtml::beginForm() where I had many form elements using ajax. I struggled for days to get the jquery to work the way I wanted, only to get no POST data in my controller when I was finally ready to submit and process the form. After several hours, I discovered it was a misplaced </div> in my view file. I had a <div class=“form”> at the beginning of my view file. The result of the misplaced </div> actually closed my <div class=“form”> BEFORE the CHtml::button(…), therefore zapping my POST data…[/size]

I think it’s may be pass a random id…

for e.g…


       	echo CHtml::ajaxlink('Show All', array('liquor/index'), array(

            "type" => "GET",

            "data" => array("vid" => $vid, "ajax" => true,"type" => '-1','value'=>'js:jQuery("#search_value_liquor").val()'),

            "success" => "function(data){

            		var value=jQuery('#search_value_liquor').val();





            "beforeSend" => "function(){ jQuery('.manage_floor').addClass('loading'); }",

                "complete" => "function(){ jQuery('.manage_floor').removeClass('loading'); }"

             ), array('live' => false, 'class' => 'blue', 'id' => rand(0,99999)));


Thanks Lynette, I will double check just in case I have a similar situation, for sure such a simple error can be difficult to spot and lead to crazy behavior.

Thanks Maggie, it’s a good point. I specified an id in the HTTP options array and got the same result :( but probably I am now one step closer to the solution.

Now, I was making some tests and noticed that when I place the link in the view php file and click it, it produces a POST call but when I place the link inside the CJuiDialog and click it, a GET call is produced. When I put the link in both places and click on the one in the CJuiDialog it works properly (but works only with the static data specified in the ajaxLink definition in the view, which doesn’t work for me since that data must be specified according to the data in the dialog).

I am not sure what this means but I’ll read about how HTTP POST and GET work to figure out the solution.

Any suggestions appreciated :D


Can you post the generated javascript?

check this wiki

i hope it’s may be some help…

Hi Diego,

As zaccaria suggests in his post on the thread you quoted, I also would remove ajaxLink inside a dialog. I would use a plain link instead, and add an event handler to the link using jQuery.on() outside the dialog.

Thanks for your help guys!

<a href="/myYiiSite/index.php?r=showCategory">Show all items of this category</a>

[quote name=‘softark’]Hi Diego,

As zaccaria suggests in his post on the thread you quoted, I also would remove ajaxLink inside a dialog. I would use a plain link instead, and add an event handler to the link using jQuery.on() outside the dialog.

Nice, I will give it a shot. Before I tried with a plain link in the dialog that would execute a function in the view which contained a jQuery.ajax, but I had the problem that the context of the Dialog is different from the context of the view, so the function was not reachable. Any advise on this?

Thanks again!


Thanks for sharing, I think this case is not exactly the same but quite similar, I’ll try some of the options in the example. :)

have you try the

asyc: false,

Thanks for the guidance, I was able to solve my problem!

Now I am importing the function that contains a jQuery.ajax(…)

<script src="js/myfunctions.js"></script>

such function is executed when a button is clicked.

<button onclick=‘updateDetails()’>Show all items of this category</button>

Using the type : "POST" and data: {} options in the ajax works perfectly.

Thanks to everyone!