0

I am new to cakephp when i am trying to make dynamic drop down list of cities on the basis of states then i am getting this error

The connection was reset.

My js code is

$(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);
  }
  });
});
});

And for this i am using function checkcity on User controller. here is my user controller file.

 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')));
}
}  

Now when i put this line in my controller file

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

then i get this error. Can anybody tell me what is the issue in it?

Ajay Kadyan
  • 1,081
  • 2
  • 13
  • 36

1 Answers1

2

What I think, you missed one closing bracket. Kindly check if it is not working for you. It should be:

$this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name'))));
Arun Jain
  • 5,476
  • 2
  • 31
  • 52