【问题标题】:Ajax call to php function in a controllerAjax 调用控制器中的 php 函数
【发布时间】:2010-11-26 04:47:34
【问题描述】:

我正在使用下面的 jquery 代码在我的控制器 CS 中调用 ajax 函数。搜索是函数名。如何在控制器中调用该函数。但我应该在这个函数内的页面文本框中得到一个值。基本上这是用于自动完成功能。上键时调用该函数。但我无法获取文本框中的值来进行相关搜索。请回复您认为对我有帮助的任何内容。提前致谢。

$(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();

});

【问题讨论】:

    标签: php jquery codeigniter


    【解决方案1】:

    你需要给输入框绑定自动补全:

    $(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();
    
    });
    

    【讨论】:

      猜你喜欢
      • 2014-11-18
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多