0

当我尝试根据州制作动态城市下拉列表时,我是 cakephp 新手,然后我收到此错误

The connection was reset.

我的js代码是

$(document).ready(function(){
$('#UserState').change(function(){
  var stateid=$(this).val();
  $.ajax({
  type: "POST",
  url: "checkcity",
  data:'stateid='+stateid+'&part=checkcity',
  success: function(data) {
  $("#city_div").html(data);
  }
  });
});
});

为此,我在用户控制器上使用功能 checkcity。这是我的用户控制器文件。

 class UsersController extends AppController {
 public $uses=array('User', 'City','State');
 function index(){

  }
  public function add() {

    $this->set('states_options', $this->State->find('list', array('fields' =>array('id','name') )));
$this->set('cities_options', array());
    if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

public function checkcity(){
$this->layout=false;
$stateid=$this->request->data['stateid'];
$this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name')));
}
}  

现在当我把这一行放在我的控制器文件中

       $this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name')));

然后我得到这个错误。谁能告诉我其中有什么问题?

4

1 回答 1

2

我认为,您错过了一个右括号。请检查它是否不适合您。它应该是:

$this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name'))));
于 2012-07-17T10:44:22.193 回答