2016-10-05 6 views
0

私はMVCフレームワークcakephpで作業しています。文字を追加したり削除しても(オートクレーモの目的を知っていても)、入力に書き込まれた各値を回復する必要があります。この値を入力して、suggesterのリストを含むjsonファイルを生成するアクションに送ります。オートコンプリート用の入力内に値を取得

これはjavascriptの私の関数である。

$(document).ready(function() { 
var autotext; 
      $('#searchItem').on("input",function() { 
     autotext = $('#divResult').html($(this).val()); 

      console.log(autotext); 
     }); 
     $('#searchItem').autocomplete({ 

      data: { mot:autotext }, 
      source: 'getAutocomplete.json', 

      dataType: "json", 
      minLength: 2 

     }); 

     }); 

何も enter image description here

を起こりませんそして、私は値を取得するときに私のコントローラでそれを使用するために、入力からデータを送信します。

$forsearch=$this->request->data['mot']; 

このエラーは、 'mot'というインデックスが未定義です。 私のコントローラの入力値を取得するには?

答えて

1

これは、ユーザーが何か入力するたびに入力の値を取得するためのコードです。それをコントローラに送ります。

$(document).ready(function(){ 
    $("#input").keyup(function(){ 
     console.log($(this).val()); 

     $.ajax({ 
     url: "controller", 
     type: "get", 
     data:{text: $(this).val()}, 
     success: function(response) { 
      //here is where you treat the JSON 
     }, 
     error: function(xhr) { 
      //if stuff goes bad 
     } 
     }); 
    }); 
    }); 

"#input"は入力フィールドのIDです。

私はajaxを使用して入力値をコントローラに送信しています。

関連する問題