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();
if(request)
{
request.open("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
request.send(requestbody);
}
}
}
In index.php or controller or something like this:
if(isset($_POST['data']))
echo "OK";
How can I transfer from this to Yii code?