当我尝试根据州制作动态城市下拉列表时,我是 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')));
然后我得到这个错误。谁能告诉我其中有什么问题?