Dynamic Ajax Select works on windows localhost but on linux server doesn't show the cities , cakephp 2.4! :( any tips?

// layout default !:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->Html->charset(); ?>
<title>
<?php echo $title_for_layout; ?>
</title>
<?php
echo $this->Html->script(''jquery'');
echo $this->Html->meta(''icon'');

echo $this->Html->css(''cake.generic'');

?>
</head>
<body>
<div id="container">
<div id="header">
<h1>Dynamic Select Box Demonstration</h1>
</div>
<div id="content">

<?php echo $this->Session->flash(); ?>

<?php echo $content_for_layout; ?>

</div>
<div id="footer">
footer
</div>
</div>
<?php //echo $this->element(''sql_dump''); ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<!-- scripts_for_layout -->
<?php echo $scripts_for_layout; ?>
<!-- Js writeBuffer -->
<?php
if (class_exists(''JsHelper'') && method_exists($this->Js, ''writeBuffer'')){ echo $this->Js->writeBuffer(); }
// Writes cached scripts

?>
</body>
</html>


// controller :


<?php

App::uses(''AppController'', ''Controller'');

class HomesController extends AppController {
var $components = array(''RequestHandler'');
var $helpers = array(''Js'');

function beforeFilter() {

$this->loadModel(''Estado'');
$this->loadModel(''Cidade'');
}

function index() {
$this->set(''title_for_layout'', ''Example of dynamic select box with cities and states in Brazil '');
$this->set(''estados'', $this->Estado->find(''list''));
}

public function getPorCidade() {

$bolete = $this->request->data[''Cidade''][''estado_id''];

$this->layout = true;
if($bolete == ''''){
$discriminas = ''<< error >>'';
}else{

$discriminas = $this->Cidade->find(''list'', array(
''conditions'' => array(''Cidade.estado_id'' => $bolete),
''recursive'' => -1
));
}

$this->set(''discriminas'',$discriminas);
$this->layout = ''ajax'';
}

}


// models :

//Home:

<?php

class Home extends AppModel {
public $useTable = false;
}

?>

//Estado:

<?php

App::uses(''AppModel'', ''Model'');

class Estado extends AppModel {

public $displayField = ''uf'';

public $hasMany = array(
''Cidade'' => array(
''className'' => ''Cidade'',
''foreignKey'' => ''estado_id'',
''dependent'' => false,
''conditions'' => '''',
''fields'' => '''',
''order'' => '''',
''limit'' => '''',
''offset'' => '''',
''exclusive'' => '''',
''finderQuery'' => '''',
''counterQuery'' => ''''
)
);

}

//Cidade:

<?php

App::uses(''AppModel'', ''Model'');

class Cidade extends AppModel {

public $displayField = ''nome'';

public $belongsTo = array(
''Estado'' => array(
''className'' => ''Estado'',
''foreignKey'' => ''estado_id'',
''conditions'' => '''',
''fields'' => '''',
''order'' => ''''
)
);

}
?>


// views :

index:

<table width="100%">
</td><td></td>
</table>
<div class="form">
<?php echo $this->Form->create(''Cidade''); ?>
<fieldset>
<legend><?php echo __(''Example of dynamic select box with cities and states in Brazill''); ?></legend>
<?php echo $this->Form->input(''estado_id'', array(''type'' => ''select'', ''options'' => $estados, ''id'' => ''estados'', ''empty'' => ''select a estado'')) ?>
<?php echo $this->Form->input(''cidade_id'', array(''type'' => ''select'', ''id'' => ''cidada'', ''empty'' => ''select a cidade'')) ?>
</fieldset>
<?php echo $this->Form->end(); ?>
</div>
<?php
$this->Js->get(''#estados'')->event(''change'',
$this->Js->request(array(
''controller''=>''Homes'',
''action''=>''getPorCidade''
), array(
''update''=>''#cidada'',
''async'' => true,
''method'' => ''post'',
''dataExpression''=>true,
''data''=> $this->Js->serializeForm(array(
''isForm'' => true,
''inline'' => true
))
))
);


?>

//get_Por_Cidade:

<?php foreach ($discriminas as $key => $value): ?>

<option value="<?php echo $key; ?>"><?php echo /*$key." - ".*/$value;?></option>

<?php endforeach; ?>

* List item

If its working in your local environment then nothing should be wrong with your PHP code.

Are you getting any JS errors in the browser console?

Well this screenshot has no JS console present.

Right click in the browser => Inspect and then go into the Console tab.

But anyways these are all general webdev questions and not anything specific to CakePHP

the views are in place, any ideas?

Server using CentOs.

Well as the error says: Do you have a file located in app/View/Homes/get_por_cidade.ctp ?

yes have…!!!

your file is called get_Por_Cidade.ctp not get_por_cidade.ctp
Watch upper and lowercase letters.

Linux generally uses a case-senstiive file-system (which not all operating systems use per default)
Therefore it could be, that this worked in another OS which used a case-insensitive filesystem

It worked master, I changed everything to lowercase (getporcidade) within the controller method, within the script and in the view name and it appeared. I even took the get_por_city from the view.

Thank you very much !!

1 Like