私はコードイグナイターを使用していて、コードイグナイターフォームヘルパーを使用してフォームを作成し、データベースからのデータを含む2つのドロップダウンボックスをロードしました。これは完全に機能します。そして、すべてのフィールドに入力すると機能します。現在、2つの必須フィールドがあります。そしてそれらの1つは必要ありません。すべての必須フィールドに入力すると機能しますが、1つの必須フィールドに入力しない場合からです。このエラーが発生します:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: Cities
Filename: admin/adddivelocation_view.php
Line Number: 67
行番号67のコードは次のとおりです。
echo form_dropdown('duikplaats', $Cities, '', $attributes_dropdown_gemeente);
次のようなビューで$citiesを取得します。
function addDiveLocation()
{
$data['Cities'] = $this->admin_model->getCity();
$data['Countries'] = $this->admin_model->getCountries();
$this->is_logged_in('admin/adddivelocation_view', $data);
}
2つのドロップダウンメニューの値または属性が変更される私のスクリプトは次のとおりです。
$('#duikplaats').change(function(){
var data = {
'id': $(this).val()
}
$.get(CI.base_url + "/admin/changeCountry", data, function(content){
console.log(content);
$('#duikland option:selected').removeAttr('selected');
$('#duikland option').filter(function(){
return $(this).val() == content;
}).attr('selected', true);
});
});
//Wanneer Land gekozen word
$('#duikland').change(function(){
var data = {
'id': $(this).val()
}
$.get(CI.base_url + '/admin/changeCity', data, function(content){
$('#duikplaats').empty();
var landen = $.parseJSON(content);
$.each(landen, function(k, v){
$('#duikplaats').append(
'<option value="' + k + '">'+ v + '</option>'
);
});
});
});
jQuery関数が呼び出す2つの関数: changeCountry:
function changeCountry(){
$query = $this->admin_model->getCountry($this->input->get('id'));
$this->output->set_output($query->FK_LandID);
}
changeCity:
function changeCity(){
$query = $this->admin_model->getCities($this->input->get('id'));
foreach($query as $object)
{
$data[$object->id] = $object->Gemeente;
}
$data = json_encode($data);
$this->output->set_output($data);
}