Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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/4/json/13.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自动完成json_Jquery_Json - Fatal编程技术网

jquery自动完成json

jquery自动完成json,jquery,json,Jquery,Json,我正在尝试在表单上进行自动完成输入,但在获取要显示的数据时遇到问题。关于这一点有很多帖子,但也有很多不同的方法。我一直在努力学习jquery站点上的示例,但我想我只是没有得到正确的返回数据?我的页面看起来像: <html> <head> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="

我正在尝试在表单上进行自动完成输入,但在获取要显示的数据时遇到问题。关于这一点有很多帖子,但也有很多不同的方法。我一直在努力学习jquery站点上的示例,但我想我只是没有得到正确的返回数据?我的页面看起来像:

<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>

<script type="text/javascript">                                         
$(document).ready(function() {
    $( "#Codes" ).autocomplete({
        source: function( request, response ) {
            $.ajax({                   
                   url: "/jreqlib",
                   dataType: "json",
                   data: {
                       featureClass: "P",
                       style: "full",
                       maxRows: 25,
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                            return {
                                label: item.name,
                                value: item.name
                            }
                        }));
                    }
                });
        },
        minLength: 1,
        open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
        },
        close: function() {
            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
        }
   });
});
    </script>
</head>
<body>
<form>
    <input id="Codes">
</form>
</body>
</html>
我喜欢的是,当我在框中单击时,它会显示“1234”和“567”,如果我键入1,则会显示“1234”和“134”,如果我键入12,则只会显示“1234”

任何帮助都将不胜感激
TIA

我的建议是让服务器根据搜索字符串动态生成json。在
maxRows:25,
下面插入
name\u startsWith:request.term
。服务器现在可以在
name\u startsWith
get变量中找到搜索字符串。对于搜索字符串“1”,服务器可能会以
[“1234”,“134”]
响应

此外,删除

featureClass: "P",
style: "full",
maxRows: 25,
替换

response( $.map( data, function( item ) {
    return {
        label: item.name,
        value: item.name
    }
}));


在您尝试使用item.name之前,我没有使用jquery的自动完成功能,但您的json不包含name。我尝试更改json,使其为[{“name”:“1234”}、{“name”:“134}等,但仍然无法使用:(
response( $.map( data, function( item ) {
    return {
        label: item.name,
        value: item.name
    }
}));
response(data);