やあ
入力フィールドのオートコンプリート機能を実行しようとしています。
疑似コード
<input type="text"/>
<script>
var ref,resp;//Global Variables
$('input').live('keyup',function(){
/* Get the input offset, so that list container can be palced at the bottom of the input once get the values through Ajax call */
ajaxCall();
/***
Here I want to write a code to create a div and place the values with in the div and show at the respective input field.
***/
});
function ajaxCall(){
var ref = new XMLHttpRequest();
ref.open();
ref.readStateChange = function(){
if(ref.readyState == 4 && ref.status ==200)
resp = ref.responseText();
}
ref.send();
}
</script>
私がここで得ている問題は、ajax readyState が 4 で値が取得されたら、ajax 呼び出しの後のコードの部分を実行する必要があることです。
しかし、readyState が 1 (他の状態の後に呼び出されていない) の場合にそのコードが実行され、データベースから値が取得されません。リストを表示できません。
注:以下の部分をajaxCallに入れることができることは知っていますが、その場所に設定できる変数がいくつか含まれています....
私の問題は理にかなっていますか?もしそうなら、誰かが私に解決策を教えてもらえますか...