How To Do Ajax And Javascript In Yii

Can someone explain to me how ajax and javascript work in Yii. The wiki about ajax and javasript for yii make me confused. Im totally new with javascript and ajax. Try to make something like that:

HTML file has :

<input type="button" onClick = "sendData('site/index.php',aTextBox.value)" name="submit" value ="Submit">

in verySimpleAjax.js

First function:

 function createRequest() {

    var r= false;  

    if (window.XMLHttpRequest) {

        r = new XMLHttpRequest();


    else if (window.ActiveXObject) {

       r = new ActiveXObject("Microsoft.XMLHTTP");


    return r;


Second function:

function sendData(link, aValue)  


           request = createRequest();


	   {"POST", link, true);

 	        var requestbody ="data="+encodeURIComponent(aValue);

		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		

		request.onreadystatechange = function()


			if (xhr.readyState == 4 && xhr.status == 200) 


	 		      document.getElementById("divID").innerHTML = request.responseText;							

	        	   } // end if

			} // end anonymous call-back function





In index.php or controller or something like this:


echo "OK";

How can I transfer from this to Yii code?

Yii comes with jQuery, so you would do it as explained on

$.post("site/index.php", {

  data: aTextBox.value

}, function(data) {




I appreciate your help, Tsunami. But I know only basic Javascript, have no idea what’s so called jQuery.