ajax没有显示HTML数据

时间:2015-06-25 08:02:05

标签: codeigniter codeigniter-2

  

//查看ajax不会从控制器返回数据。视图返回[object],[object]           ajax不从控制器返回数据。 View返回[object],[object] ajax不从控制器返回数据。 View返回[object],[object] ajax不从控制器返回数据。 View返回[object],[object] ajax不从控制器返回数据。 View返回[object],[object] ajax不从控制器返回数据。视图返回[object],[object]

<script type="text/javascript">  
                  $(document).ready(function() {  

                     $.ajax({  
                         url: "<?= site_url('products/getallvariance') ?>", 
                      type:"GET",
                      dataType:"html",
                         success:function(data){ 
                         alert('fahad');
                       //  alert(data);  
                            $('#prTable2').html(data);  
                     }  
                     ,error: function(data)

                     {
                     alert (data);
                     }
                  });  

            });  
</script>  

//controller get value from the model but not showing data into view through ajax. ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]
function getallvariance()
    {

        $variance['allvariance'] = $this->products_model->getvariance();

        $output = '<tbody>';

      foreach ($variance['allvariance'] as $row)  
      {  

         $output .= '<tr><td colspan="10" class=" sorting_1">'.$row->name.'</td></tr>';  
      }
      $output .= '</tbody>';

      echo $output; 

    }

//model is the query is correct? ajax not return data from the controller. View returns [object], [object] ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]ajax not return data from the controller. View returns [object], [object]

function getvariance()
{
    $this->db->select('name,  IFNULL( quantity, 0 ) AS quantity');
    $q = $this->db->from('products');

    if ($q->num_rows() > 0) {
            foreach (($q->result()) as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return FALSE;
}

1 个答案:

答案 0 :(得分:0)

您的模型函数始终为return FALSE,因为您无法获取数据,并且在foreach() loopmodel中的controller中使用了两次<?php function getvariance() { $this->db->select('name, IFNULL( quantity, 0 ) AS quantity'); $this->db->from('products'); $q= $this->db->get(); if ($q->num_rows() > 0) { return $q->result(); } else { return FALSE; } } 数据你的代码错了。这将是

<强>模型

function getallvariance() {
    $this->load->model('products_model');// load your model
    $variance = $this->products_model->getvariance();
    if($variance){

    $output = '<tbody>';

    foreach ($variance as $row) {

        $output .= '<tr><td colspan="10" class=" sorting_1">' . $row->name . '</td></tr>';
    }
    $output .= '</tbody>';
    }else{
    $output="error";
    }

    echo $output;
}

<强>控制器

 var goToProfileVar = String()
 var goToProfileVar2 = String()

func goToCell103(cell: mainCell)
{
    var goToCell103:mainCell? = cell as mainCell
    var indexPath: NSIndexPath  = self.resultsTable.indexPathForCell(goToCell103!)!

    goToProfileVar = cell.usernameLbl.text!
    goToProfileVar2 = cell.objectid.text!
           println("\(goToProfileVar) first.")
    println("\(goToProfileVar2) first.")



}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {



    if (segue.identifier == "goToProfile8") {
        var svc = segue.destinationViewController as! generalProfileLast;
        svc.dataPassed = goToProfileVar}

   else if (segue.identifier == "goToLikers1") {
        var svc = segue.destinationViewController as! likers;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments1") {
        var svc = segue.destinationViewController as! enterCommentVC;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments2") {
        var svc = segue.destinationViewController as! commenters;
        svc.dataPassed = goToProfileVar2}

      println("\(goToProfileVar) second.")
     println("\(goToProfileVar2) second.")

}