2009-09-07 15 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(); 

});