在cakephp 2.x中从视图到控制器进行jquery ajax调用

我试图从视图到控制器发出ajax请求,ajax requst工作正常,但是从控制器没有任何东西返回到视图。 我不知道问题出在哪里..我正在尝试的是在我看来我正在从控制器显示一些数据,并且有一个选择框。 当我从选择框中选择一个城市时,它会调用ajax请求,并应在view.ctp中显示该特定城市的结果。

$('#cityid').change(function() { $city_id= $('#cityid :selected').val(); alert($city_id); $.ajax({ url : " 'deals', 'action' =>'topdeals'), true); ?>", type : "POST", cache : false, data : {city_id: city_id}, success : function(data){ alert(data); } }); }); }); 

并在视图中

  
Form->create('Deal', array('action'=>'topdeals','type'=>'post'));?> Form->input('city_id', array('label'=>'City','type'=>'select', 'id'=>'city_id','empty'=>'select City','options' =>$city)); echo $this->Form->end(); ?>

并在控制器中

  function topdealajax() { $this->log('Ajax call -----------------'); if ($this->request->isAjax()) { $this->log('inside if request is ajax -----------------'); $this->layout = null; $this->view = 'topdeals'; if(!empty($this->request->data)) { $this->log('inside if not empty of params -----------------'); $data = $this->request->data['city_id']; $this->log($data); $city_id=$data['city_id']; $this->log($city_id); $city_id= $this->request->data['city_id']; // $this->log($city_id); $topDealSortbyRank1=$this->Deal->find('all', array('conditions'=>array('date_expiry >=' =>date('Ymd ') , 'date_expiry  'date_expiry','Deal.city_id'=>$city_id),'order'=>array('Deal.deal_rank ASC'))); //$this->log($topDealSortbyRank1); $this->set('topdealsortbyrank',$topDealSortbyRank1); $this->render('topdeals'); } } } 

 /*IN THE AJAX REQUEST YOU SHOULD HAVE*/ $.ajax({ ..... success: function(data){ $('#MYDIV').html(data);}, //YOU CAN APPEND OR REPLACE THE CONTENT OF A CONTAINER WITH THE RESPONSE ... }); //in DealsController::topdeals() you should have at the begining if ($this->request->isAjax()): $this->layout = null; $this->view = 'view_ajax'; //Other view that doesn't needs layout, only if necessary endif; /*DO WHATEVER YOU WANT HERE, SEND IT TO THE VIEW, THE VIEW GETS RENDERD AND RETURN AS A RESULT*/