douhoushou8385 2014-06-11 04:35
浏览 45

将数组变量传递给ajax cakephp

I am trying to implement something like this where a user can select multiple conditions to search. My approach is to populate an array with selected conditions and pass it via ajax to make a request. I have the following codes in my ajax

$( document ).ready(function() {


  <?php 
        //$array = array();
        $array["a"] = "Foo";
        $array["b"] = "Bar";
        $array["c"] = "Baz";
        $array["d"] = "Wom"; 
        $y = serialize($array);
        //$str = 'Yomi';
    ?>

  var y = '<?php echo $y ; ?>';

  $('.elementtosort').click(function(e){
    $.ajax({
          url: "http://localhost/elegante/weafe_length_prices/results/",
          data: y,
          cache: false,
          type: 'GET',
          dataType: 'Html',
          success: function (data) {
              $('#context').html(data);
          }
 });
});
});

and in my action i am trying to debug what was passed but keep getting strange results after each tweak

     public function results(){
     if ($this->request->is('ajax')) {
          debug($_REQUEST);
          $this->render('filtered','ajax');
     }


}

I'll appreciate any help!

  • 写回答

2条回答 默认 最新

  • douben1891 2014-06-11 04:45
    关注

    Please change from

    $y = serialize($array);
    

    to

    $y = json_encode($array);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号