Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery自动完成变量php文件到源代码_Php_Jquery - Fatal编程技术网

jquery自动完成变量php文件到源代码

jquery自动完成变量php文件到源代码,php,jquery,Php,Jquery,我尝试使用jquery ui autocomplete函数从变量php文件加载数据,具体取决于用户选择的单选按钮,但我无法检索任何数据,而是出现以下错误: jquery-ui.js:6015 Uncaught TypeError: this.source is not a function at $.(anonymous function).(anonymous function)._search (https://code.jquery.com/ui/1.12.1/jquery-ui.

我尝试使用jquery ui autocomplete函数从变量php文件加载数据,具体取决于用户选择的单选按钮,但我无法检索任何数据,而是出现以下错误:

jquery-ui.js:6015 Uncaught TypeError: this.source is not a function
    at $.(anonymous function).(anonymous function)._search (https://code.jquery.com/ui/1.12.1/jquery-ui.js:6015:8)
    at $.(anonymous function).(anonymous function)._search (https://code.jquery.com/ui/1.12.1/jquery-ui.js:144:25)
    at $.(anonymous function).(anonymous function).search (https://code.jquery.com/ui/1.12.1/jquery-ui.js:6007:15)
    at $.(anonymous function).(anonymous function).search (https://code.jquery.com/ui/1.12.1/jquery-ui.js:144:25)
    at $.(anonymous function).(anonymous function).<anonymous> (https://code.jquery.com/ui/1.12.1/jquery-ui.js:5988:10)
    at handlerProxy (https://code.jquery.com/ui/1.12.1/jquery-ui.js:641:6)
jquery ui.js:6015未捕获类型错误:this.source不是函数
在$(匿名函数)。(匿名函数)。\u搜索(https://code.jquery.com/ui/1.12.1/jquery-ui.js:6015:8)
在$(匿名函数)。(匿名函数)。\u搜索(https://code.jquery.com/ui/1.12.1/jquery-ui.js:144:25)
在$(匿名函数)。(匿名函数)。搜索(https://code.jquery.com/ui/1.12.1/jquery-ui.js:6007:15)
在$(匿名函数)。(匿名函数)。搜索(https://code.jquery.com/ui/1.12.1/jquery-ui.js:144:25)
在$(匿名函数)。(匿名函数)。(https://code.jquery.com/ui/1.12.1/jquery-ui.js:5988:10)
在handlerProxy(https://code.jquery.com/ui/1.12.1/jquery-ui.js:641:6)
这是我的代码:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

<script>
$(function(){

    var selected;
    var search_php;

    $('#myForm input').on('change', function() {
        selected = $('input[name=radioName]:checked', '#myForm').val();

        if(selected == 1)
        {
            search_php = '"' + "name_search.php" + '"';
            console.log(search_php);
        }
        else if(selected == 2)
        {
            search_php = '"' + "brand_search.php" + '"';
            console.log(search_php);
        }
        else if(selected == 3)
        {
            search_php = '"' + "serial_search.php" + '"';
            console.log(search_php);
        }
        else if(selected == 4)
        {
            search_php = '"' + "location_search.php" + '"';
            console.log(search_php);
        }
    });

    $('#txtSearch').autocomplete({
        source: search_php,
        minLength: 3
    }).data("ui-autocomplete")._renderMenu = function (ul, items) {
                $("#table_body tbody tr").remove();
                $.each( items, function( index, item ) {
                var table = $("#table_body");
                if (item.items_name != '#') {
                table.append("<tr><td>"+item.items_name+"</td><td>"+item.items_brand+"</td><td>"+item.item_serial+"</td><td>"+item.location_name+"</td><td>"+item.items_desc+"</td>");
                }
                else
                {
                    $("#table_body tbody tr").remove();
                }
                });
            };

    $('#txtSearch').keyup(function(event){ 
        //run the character number check  
        if($('#txtSearch').val().length < 3){  
            $("#table_body tbody tr").remove();
        }
    });

});
</script>

$(函数(){
选择var;
var搜索;
$('#myForm input')。在('change',function()上{
selected=$('input[name=radioName]:选中','#myForm').val();
如果(所选==1)
{
search_php='“+”name_search.php“+”;
log(search_php);
}
else if(所选==2)
{
search_php='“+”brand_search.php“+”;
log(search_php);
}
否则如果(所选==3)
{
search_php='“+”serial_search.php“+”;
log(search_php);
}
否则如果(所选==4)
{
search_php='“+”位置_search.php“+”;
log(search_php);
}
});
$('#txtSearch')。自动完成({
来源:search_php,
最小长度:3
}).data(“ui自动完成”)。\u renderMenu=功能(ul,项){
$(“#工作台#车身tr”).remove();
$。每个(项目、功能(索引、项目){
var table=$(“#table_body”);
如果(item.items_name!='#'){
表.追加(“+项目.项目名称+”“+项目.项目品牌+”“+项目.项目系列+”“+项目.位置+项目名称+”“+项目.项目描述+”);
}
其他的
{
$(“#工作台#车身tr”).remove();
}
});
};
$('#txtSearch').keyup(函数(事件){
//运行字符号检查
if($('#txtSearch').val().length<3){
$(“#工作台#车身tr”).remove();
}
});
});

我通过添加一个外部函数(
getData
)将其传递到
autocomplete
函数中的
source
,首先从我的php文件中获取响应,然后通过
autocomplete
函数将其提取到我的表中,从而实现了我所需的功能

我的新代码:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

<script>
$(function(){

    var selected = 1;
    var search_php = "name_search.php";

    $('#myForm input').on('change', function() {
        selected = $('input[name=radioName]:checked', '#myForm').val();

        if(selected == 1)
        {
            search_php = "name_search.php";
        }
        else if(selected == 2)
        {
            search_php = "brand_search.php";
        }
        else if(selected == 3)
        {
            search_php = "serial_search.php";
        }
        else if(selected == 4)
        {
            search_php = "location_search.php";
        }
    });

    var getData = function (request, response) {
            $.ajax({
              type: "POST",
              url:search_php,
              data: request,
              success: response,
              dataType: 'json'
            });
    };

    $('#txtSearch').autocomplete({
        source: getData,
        minLength: 3
    }).data("ui-autocomplete")._renderMenu = function (ul, items) {
                $("#table_body tbody tr").remove();
                $.each( items, function( index, item ) {
                var table = $("#table_body");
                if (item.items_name != '#') {
                table.append("<tr><td>"+item.items_name+"</td><td>"+item.items_brand+"</td><td>"+item.item_serial+"</td><td>"+item.location_name+"</td><td>"+item.items_desc+"</td>");
                }
                else
                {
                    $("#table_body tbody tr").remove();
                }
                });
            };

    $('#txtSearch').keyup(function(event){ 
        //run the character number check  
        if($('#txtSearch').val().length < 3){  
            $("#table_body tbody tr").remove();
        }
    });

});
</script>

$(函数(){
选择的var=1;
var search\u php=“name\u search.php”;
$('#myForm input')。在('change',function()上{
selected=$('input[name=radioName]:选中','#myForm').val();
如果(所选==1)
{
search\u php=“name\u search.php”;
}
else if(所选==2)
{
search\u php=“brand\u search.php”;
}
否则如果(所选==3)
{
search\u php=“serial\u search.php”;
}
否则如果(所选==4)
{
search\u php=“location\u search.php”;
}
});
var getData=函数(请求、响应){
$.ajax({
类型:“POST”,
url:search_php,
数据:请求,
成功:回应,
数据类型:“json”
});
};
$('#txtSearch')。自动完成({
资料来源:getData,
最小长度:3
}).data(“ui自动完成”)。\u renderMenu=功能(ul,项){
$(“#工作台#车身tr”).remove();
$。每个(项目、功能(索引、项目){
var table=$(“#table_body”);
如果(item.items_name!='#'){
表.追加(“+项目.项目名称+”“+项目.项目品牌+”“+项目.项目系列+”“+项目.位置+项目名称+”“+项目.项目描述+”);
}
其他的
{
$(“#工作台#车身tr”).remove();
}
});
};
$('#txtSearch').keyup(函数(事件){
//运行字符号检查
if($('#txtSearch').val().length<3){
$(“#工作台#车身tr”).remove();
}
});
});