dongnuo6310 2014-12-31 08:48
浏览 37

AJAX返回数据错误?

please, could you help me with this problem?:

I'm getting products sorted ASC or DESC by title or price. If I sort them ASC, there is no problem - I loop products in foreach and adding generated string into variable. But if products are sorted DESC, there is problem - I'm looping them via foreach but html is not adding into variable (I tried to print_r variable $products, so I know, it wasn't empty..) - I hope that if you look at code bellow, my question would be clear. Do you know, where might be problem? Thank you very much.

I also tried to call this code not via ajax, but go to the url of ajax script and behavior is same...

EDIT: I tried to echo $products_html before adding $products_html into $return['products_html'] and in $products_html is correctly generated html... I'm quite confused what does this mean...

EDIT 2: when I print_r $return, it is all ok - products html is stored in $return['products_html']. Problem is, when I json_encode it. But I really don't know, where is the problem...

Here is code:

$products_html = '';
$products = $this->products_model->get_products_specified($filter); // here i load products into variable
foreach($products as $product){ // here i loop them
            $products_html .= view_loader('products/product_small', array('product' => $product), true); // view load returns html for product
        }
$return['products_html'] = $products_html;
        $return['params_url'] = base_url().'individual/'.generate_url_from_parameters($filter);
        $return['status'] = 1;
        $return['filter'] = $filter;
        echo json_encode($return); // echo for ajax return
  • 写回答

1条回答 默认 最新

  • dongtan1845 2014-12-31 08:55
    关注

    If the datatype for the field you are sorting is other than an Numeric datatype like varchar, then that might be the problem.

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本