Welcome Guest, Not a member yet? Register   Sign In
codeigniter vs ajax [please help a noob]
#1

[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);
?&gt;

example [html]
Code:
&lt;html&gt;
&lt;head&gt;
[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]
&lt;/head&gt;
&lt;body&gt;

&lt;form&gt;
&lt;input type="button" value="cliccami" name="bottone" /&gt;
&lt;/form&gt;
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

&lt;/body&gt;
&lt;/html&gt;


The original example is this:
http://www.w3schools.com/php/php_ajax_database.asp


Messages In This Thread
codeigniter vs ajax [please help a noob] - by El Forum - 01-04-2012, 10:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB