[eluser]lord_nerevar[/eluser]
hi all.
i am studying how does ajax works to improve my skills.
i begin with a simple php example (no codeigniter) and i modified that to use with my database. all ok. now i was trying to understand how to use ajax with codeigniter, but after hours of researches i am still at zero.
can anyone explain to me how convert this simple example into a codeigniter mvc example?
i think this is best method for me to learn use codeigniter and ajax and this can help other noob users like me to begin to use ajax with ci!
thanks a lot!
example [php]:
Code:
<?php
$con = mysql_connect('localhost', 'root', 'root');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$sql="SELECT * FROM commenti";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>codc</th>
<th>data</th>
<th>commento</th>
<th>taskid</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['codC'] . "</td>";
echo "<td>" . $row['data'] . "</td>";
echo "<td>" . $row['commento'] . "</td>";
echo "<td>" . $row['taskid'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
example [html]
Code:
<html>
<head>
[removed]
function showComments()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint")[removed]=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php",true);
xmlhttp.send();
}
[removed]
</head>
<body>
<form>
<input type="button" value="cliccami" name="bottone" />
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
The original example is this:
http://www.w3schools.com/php/php_ajax_database.asp