AJAX help

Hello, on my home page I have subscriptions to various programs. If a user is logged in, they can see what programs they are subscribed to and which ones they aren’t subscribed to. For the latter, I plan on having a link that they can click to request access. However, I want this link to start a small AJAX query that returns true upon running successfully. I am very experienced with AJAX, but I don’t really know how it integrates with Yii. If I just wanted to run a very simple script using AJAX, how would I go about this? By the way, the script is just a quick INSERT into a database table, if it matters. Any help getting started with this is appreciated, thanks.

this is what I do rymonator…

I have a controller/action that will handle the ajax request. afterwards, in the view i write the link or button or whatever by using its htmlOptions array:


check that option on the elements of CHtml class

Thanks Antonio Ramirez! I’ll see if I can get it to work.

I just tried a quick test with js and CHTML and it doesn’t work:

echo CHtml::link("test",array('onclick'=>'javascript:alert("test")'));

the alert doesn’t even work when I click the link

You should use this way:

echo CHtml::link("test",array('onclick'=>'js:alert("test")')); // Note te diference

yeh that’s not working either…not that I want to issue an alert, but I figure before I start using AJAX I would test out a simple alert…

I understand how to use CHtml to create a link to a controller action, but to make it access that controller action via AJAX…?

I do this my friend:

CHtml::link('text--to--display', '#', array ('onclick'=>'js:alert("hello");return false;'));

tested and working :)