[eluser]ludo31[/eluser]
Hello ;
I would like to test Ajax in CI , it's my first code with Ajax so I create a simple code but my problem is how to catch the data : sometimes we use input-> post : here the case is I search via select in my view :
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ajax essai</title>
[removed]
function showUser(str)
{
var xmlhttp;
if (str=="")
{
document.getElementById("txtHint")[removed]="";
return;
}
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", "ajaxcontrolleur.php?q="+str, true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
here : the name of my controlleur where I send the parameter is ajaxcontrolleur
Code:
xmlhttp.open("GET", "ajaxcontrolleur.php?q="+str, true);
and in my controller I try to catch the parameter but it doesn't work :
Code:
class Ajaxcontrolleur extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
/* we try to catch */
$q = $this->input->get('q');
/* we find in database */
$data['infos'] = $this->modelajax->cherche($q);
/* and we send in another view file */
$this->load->view('ajax_view',$data);
}
}
so I would like ask you how to catch the value of q ??
another question did we proceed like this in Ajax with CI ?
thanks