我正在嘗試爲輸入字段執行自動完成功能。
僞代碼
<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和值retrived代碼的一部分。
但是,當readyState爲1(在其他狀態之後未調用它)時,該代碼正在執行,其中未從數據庫中檢索值。讓我無法顯示列表。
注:我知道下面的部分可以放在AjaxCall的,但它包含了一些變量,可以在地方設置....
難道我的問題有意義嗎?如果是這樣,可以讓一些機構知道解決方案...
jQuery在XmlHttpRequest上有一個很好的抽象層,即'$ .ajax'函數 –
@Alnitak是的。但正如我所提到的,一些必須在ajax調用之後執行的代碼有一些變量和數據可以在前面的功能可以設置爲只..... –
還不能確定你使用的是什麼版本的jQuery但'.live()'已經被廢棄了,因爲1.4 – wakooka