从ajax

时间:2019-02-03 09:28:09

标签: ajax codeigniter-3

我正在通过ajax获取更新的变量值,但无法在视图中使其循环显示过滤后的产品

在我的控制器中,我写道:

 $response['output']  = $product;
 $response['status']  = "success";

这是我能够在控制台中得到的响应:

output: [{id: "26", pro_id: "P856", pimg_id: "110", cat_id: null, subcat_id: null, brand_id: null,…},…]
    0: {id: "26", pro_id: "P856", pimg_id: "110", cat_id: null, subcat_id: null, brand_id: null,…}
    1: {id: "27", pro_id: "P227", pimg_id: "111", cat_id: null, subcat_id: null, brand_id: null,…}
    2: {id: "28", pro_id: "P434", pimg_id: "112", cat_id: null, subcat_id: null, brand_id: null,…}
    status: "success"

这是我的视图代码,我希望在收到Ajax响应后使其循环显示:

  

//调用产品ariable和   在ajax请求发送之前作为defalut进行循环                                                                    db-> get_where('product_image',array('pro_id'=> $ product-> pro_id))-> result();

    if(!empty($productimage[0]->img_url)){ ?>


    <img src="<?php echo base_url(); ?>assets/img/product/<?php echo $productimage[0]->img_url ?>" alt="">


    <?php $img= $productimage[0]->img_url;  ?>
                        <?php  if (empty($productimage[1])) {
                                ?>
                            <div class="hover-content">
                                <a href="<?php echo base_url() ?>Web/single_pro?P=<?php echo $product->pro_id ?>"
     

class =“ hover-image”>                                                       资产/ img /产品/ img_url吗?>“ alt =”“>                                                                                                                                                                                                           Web / single_pro?P = pro_id)吗?>“   class =“ hover-image”>                                       资产/ img /产品/ img_url吗?>“ alt =”“>                                                                                                                                                                               

            <div class="product-contents">
                <h3 class="product__caption">
                                            <a href="<?php echo base_url() ?>Web/single_pro?P=<?php echo
     

base64_encode($ product-> pro_id)?>“> pro_name   ?>                                                                                                                                                                                                                                    

                <div class="product__price">

                    <span class="price--old"><?php if ($this->session->userdata('bchrate')){ ?>
                                <?php $curr = $this->session->userdata('bchcurrency');
                            $sym= $this->web_model->get_currency($curr); echo $sym->symbol; ?>  
                                <?php $rate=$this->session->userdata('rate');
     

$ sp = $ product-> selling_price * $ rate; echo floor($ sp); ?>                           session-> userdata('bchcurrency');                                   $ sym = $ this-> web_model-> get_currency($ curr); echo $ sym->符号; ?> pro_price * $ rate); ?>                                                          ₹pro_price; ?>                                ₹selling_price; ?>                                                      

                <input type="hidden" name="proid" value="<?php echo $product->pro_id;?>">
                <input type="hidden" name="pro_price" value="<?php echo $product->pro_price;?>">
                <input type="hidden" name="selling_price" value="<?php echo $product->selling_price;?>">
                <input type="hidden" name="discount" value="<?php echo $product->discount;?>">
                <input type="hidden" name="sku" value="<?php echo $product->pro_sku; ?>">
                <input type="hidden" name="cat" value="<?php echo $product->cat_name; ?>">
                <input type="hidden" name="subcat" value="<?php echo $product->subcat_name; ?>">
                <input type="hidden" name="brand" value="<?php echo $product->brand_name; ?>">
                <input type="hidden" name="pimg_id" value="<?php echo $product->pimg_id; ?>">
                <input type="hidden" name="pro_name" value="<?php echo $product->pro_name; ?>">
                <input type="hidden" name="pro_summery" value="<?php echo $product->pro_summery; ?>">
                <input type="hidden" name="pro_details" value="<?php echo $product->pro_details; ?>">
                <p class="product-info-para">
                    product description textt.
                </p>
                <?php $pro_id=$product->pro_id; ?>
                    <div class="product__btn">
                        <a href="<?php echo base_url()?>Web/fcart/?pid=<?php echo $pro_id;?>&img=<?php echo $img
     

;?>&name = pro_name;?>&price = selling_price; ?>“ class =” theme-btn-outlined--type-2“>添加到   大车                                              

        </div>
    </div>

    <?php endforeach; ?>





 <?php foreach($product as $product): ?>
    <div class="col-lg-6 col-sm-6 mb-30">
        <div class="belly-product">
            <div class="product__image">
                <?php
    $productimage = $this->db->get_where('product_image', array('pro_id' => $product->pro_id))->result();


    if(!empty($productimage[0]->img_url)){ ?>


    <img src="<?php echo base_url(); ?>assets/img/product/<?php echo $productimage[0]->img_url ?>" alt="">


    <?php $img= $productimage[0]->img_url;  ?>
                        <?php  if (empty($productimage[1])) {
                                ?>
                            <div class="hover-content">
                                <a href="<?php echo base_url() ?>Web/single_pro?P=<?php echo $product->pro_id ?>"
     

class =“ hover-image”>                                                       资产/ img /产品/ img_url吗?>“ alt =”“>                                                                                                                                                                                                           Web / single_pro?P = pro_id)吗?>“   class =“ hover-image”>                                       资产/ img /产品/ img_url吗?>“ alt =”“>                                                                                                                                                                               

            <div class="product-contents">
                <h3 class="product__caption">
                                            <a href="<?php echo base_url() ?>Web/single_pro?P=<?php echo
     

base64_encode($ product-> pro_id)?>“> pro_name   ?>                                                                                                                                                                                                                                    

                <div class="product__price">

                    <span class="price--old"><?php if ($this->session->userdata('bchrate')){ ?>
                                <?php $curr = $this->session->userdata('bchcurrency');
                            $sym= $this->web_model->get_currency($curr); echo $sym->symbol; ?>  
                                <?php $rate=$this->session->userdata('rate');
     

$ sp = $ product-> selling_price * $ rate; echo floor($ sp); ?>                           session-> userdata('bchcurrency');                                   $ sym = $ this-> web_model-> get_currency($ curr); echo $ sym->符号; ?> pro_price * $ rate); ?>                                                          ₹pro_price; ?>                                ₹selling_price; ?>                                                      

                <input type="hidden" name="proid" value="<?php echo $product->pro_id;?>">
                <input type="hidden" name="pro_price" value="<?php echo $product->pro_price;?>">
                <input type="hidden" name="selling_price" value="<?php echo $product->selling_price;?>">
                <input type="hidden" name="discount" value="<?php echo $product->discount;?>">
                <input type="hidden" name="sku" value="<?php echo $product->pro_sku; ?>">
                <input type="hidden" name="cat" value="<?php echo $product->cat_name; ?>">
                <input type="hidden" name="subcat" value="<?php echo $product->subcat_name; ?>">
                <input type="hidden" name="brand" value="<?php echo $product->brand_name; ?>">
                <input type="hidden" name="pimg_id" value="<?php echo $product->pimg_id; ?>">
                <input type="hidden" name="pro_name" value="<?php echo $product->pro_name; ?>">
                <input type="hidden" name="pro_summery" value="<?php echo $product->pro_summery; ?>">
                <input type="hidden" name="pro_details" value="<?php echo $product->pro_details; ?>">
                <p class="product-info-para">
                    Nunc facilisis sagittis ullamcorper. Proin lectus ipsum, gravida et mattis vulputate, tristique ut lectus. Sed et
     

lorem nunc。紫茎泽兰等植物中的原发性前庭   乌贼菌Aenean eleifend laoreet congue。万岁                       

                      pro_id; ?>                                                          Web / fcart /?pid =&img =&name = pro_name;?>&price = selling_price; ?>“ class =” theme-btn-outlined--type-2“>添加到   大车                                              

        </div>
    </div>

    <?php endforeach; ?>

0 个答案:

没有答案