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:
The action function (actionShowCategory) is being executed correctly but the array $_POST is empty
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'),
'success'=>"function(content){
// 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
[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]
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.
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.
<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.
[/quote]
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?