Ajax Code:
function showProduct(baseurl,sortbyid)
{
//alert('123');
if (sortbyid=="")
{
document.getElementById("sortMyData").innerHTML="";
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("sortMyData").value=xmlhttp.responseText;
}
}
url = baseurl + 'product/sortby/'+sortbyid;
//alert(url);
xmlhttp.open("GET", url, true);
xmlhttp.send();
return false;
}
Controller:
public function sortby()
{
$lowhigh=$this->uri->segment(3);
$lowtohighprice=$this->product_model->getlowtohighprice($lowhigh);
$this->load->view('sortby');
}
Model:
public function getlowtohighprice() { $lowtohighQuery=$this->db->query("SELECT * FROM product group by price order by price ASC");
if($lowtohighQuery->num_rows() > 0)
{
foreach($lowtohighQuery->result_array() as $row)
{
$lowtohighpricedetails[]=$row;
}
return $lowtohighpricedetails;
}
}
I'm trying to fetch the products from low to high price using ajax filter.I have executed query, its working fine. I am new to ajax so i hope the prob with ajax code .I don noe where i am stuck, am using codeigniter framework. Thanks in advance.
You have to pass your data to the view, so the view can show you the query result.
public function sortby()
{
$lowhigh = $this->uri->segment(3);
$lowtohighprice = $this->product_model->getlowtohighprice($lowhigh);
// The second parameter $lowtohighprice is the data
$this->load->view('sortby', $lowtohighprice);
}