2009-09-07 35 views
2

我正在使用下面的jQuery代碼在我的控制器CS中調用ajax函數。搜索是功能名稱。如何在控制器中調用該函數。但我應該在這個函數內頁面的文本框中獲得一個值。基本上這是爲了自動完成功能。在關鍵的功能被稱爲。但我無法獲得文本框中的值來做相關搜索。請回復您認爲對我有幫助的任何事情。提前致謝。Ajax調用控制器中的php函數

$(document).ready(function(){ 
    $("#searchusers").autocomplete("http://localhost/CS/index.php/search" , { 
     width: 500, 
     selectFirst: false 
    }); 

}); 
$(document).ready(function(){ 
    $("#searchusers").result(function(event, data, formatted) { 
     if (data) 
      $(this).parent().next().find("input").val(data[1]); 
    }); 
    $('#set1 *').tooltip(); 
    $('#firstname').tooltip(); 

}); 

回答

2

您需要綁定自動完成輸入框:

$(document).ready(function(){ 
    $("#searchusers").parent().next().find("input").autocomplete("http://localhost/CS/index.php/search" , { 
     width: 500, 
     selectFirst: false 
    }); 

}); 

如果你給輸入框自己的ID,代碼變得更加清晰:

<input type="text" id="searchUsersInput"> 

然後:

$(document).ready(function(){ 
    $("#searchUsersInput").autocomplete("http://localhost/CS/index.php/search" , { 
     width: 500, 
     selectFirst: false 
    }); 

}); 
$(document).ready(function(){ 
    $("#searchUsersInput").result(function(event, data, formatted) { 
     if (data) 
       $(this).val(data[1]); 
    }); 
    $('#set1 *').tooltip(); 
    $('#firstname').tooltip(); 

});