ビューには、次のようなドロップダウン リストがあります。
<div class="input select"><label for="customer">Customer</label><select name="data[Project][customer_id]" id="customer">
<option value="16">Customer1</option>
<option value="17">Customer2</option>
</select>
私がjQueryでやろうとしているのは、ページの読み込み時またはドロップダウン選択の選択変更時に、jqueryが指定されたオプション値でコントローラー関数を呼び出し、関数から期待される戻り値を取得することです。以下はコントローラー部分です。
public function getInitials($id){
$this->autoRender = false;
if($this->request->is('ajax')){
$initials = $this->Customer->getInitialsById($id);
echo json_encode($initials);
}}
JQueryは私が得意とするものではありませんが、調査を行い、同様の機能を使用して機能させようとしましたが、何も機能せず、完全に間違ったことをしていると感じています. jQuery は次のとおりです。
jQuery(document).ready(function($){
$('#customer').change({
var initials = "";
$("select option:selected").each(function(){
initials = "<?php echo Router::url(array('controller'=>'projects','action'=>'getInitialsById')) ?>"
});
$("div").text( initials );
});
どんな助けでも大歓迎です。