【问题标题】:Ajax price filter CodeigniterAjax 价格过滤器 Codeigniter
【发布时间】:2013-09-16 15:51:31
【问题描述】:

Ajax 代码:

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;
  }

控制器:

public function sortby()
        {
            $lowhigh=$this->uri->segment(3);
            $lowtohighprice=$this->product_model->getlowtohighprice($lowhigh);
            $this->load->view('sortby');
        }

型号:

公共函数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; 
    }
}

我正在尝试使用 ajax 过滤器从低价到高价获取产品。我已经执行了查询,它工作正常。我是 ajax 新手,所以我希望有 ajax 代码的问题。我不知道我被困在哪里,我正在使用 codeigniter 框架。提前致谢。

【问题讨论】:

    标签: php ajax codeigniter


    【解决方案1】:

    您必须将数据传递给视图,以便视图可以向您显示查询结果。

    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); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 2016-04-11
      • 2015-02-21
      相关资源
      最近更新 更多