日期:2014-05-16  浏览次数:20362 次

Jquery自动完成
大家帮忙给看看,我就想做一个像百度是的,输个字符就出来好多可供选择的,现在后台一输出就变成JSON数据在前台界面显示出来了,咋回事啊,错哪了?
JScript code

$(document).ready(function() {
        $("#suggest1").autocomplete("default.aspx",{
            minChars:1,
            max:100,
            matchSubset:1,
            matchContains:1,
            cacheLength:10,
            dataType:'json',
            parse:function(data){
                var parsed = [];
                for(var i=0;i<data.length;i++)
                {
                    parsed[parsed.length]={
                        data:data[i],
                        value:data[i].city,
                        result:data[i].city
                    };
                }
                return parsed;
            },
            formatItem:function(data){
                return "<div>"+data.city+"</div>";
            },
            formatMatch:function(data){
                return data.city;
            },
            formatResult:function(data){
                return data.city;
            }
        });
//.result(function(event, data, formatted) {
//         $("#XYhidden").val(data.id);
    });


C# code

{"[{"id":"1","city":"Aberdeen"},{"id":"2","city":"Ada"},{"id":"3","city":"Adamsville"},{"id":"4","city":"Addyston"},{"id":"5","city":"Adelphi"},{"id":"6","city":"Adena"},{"id":"7","city":"Adrian"},{"id":"8","city":"Akron"},{"id":"9","city":"Albany"},{"id":"10","city":"Alexandria"},{"id":"11","city":"Alger"},{"id":"12","city":"Alledonia"}]}



------解决方案--------------------
{"[{"id":"1",
这里多了一个双引号