This is a migrated thread and some comments may be shown as answers.

Autocomplete problem json

1 Answer 233 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Alessandro
Top achievements
Rank 1
Alessandro asked on 26 Jan 2012, 10:17 AM

 public partial class GetAirport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(GetAiport(Request.QueryString["apt"]));
        }
        public string GetAiport(string term)
        {
     
              using (D4AgencyModelDataContext dc = new D4AgencyModelDataContext())
              {
                  var citta = (from city in dc.d4agency_Airport_Cities
                               join c in dc.d4agency_Countries
                               on city.Paese equals c.Code
                               where city.Airport.StartsWith(term) && (city.TypeApt.Equals('A') || city.TypeApt.Equals('C'))
                               select new
                               {
                                   city.CodAirport, city.Airport , city.City , c.Description , city.Stato
                               });          

                                             string jsonStr = JsonConvert.SerializeObject(citta);
                  return jsonStr;

              }           
        }
      

    }

Hello i have a porblem whit the autocomplete
in my page :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="D4Agency.Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
    <link href="/Jquery/Kendo/styles/kendo.common.css" rel="stylesheet"/>
    <link href="/Jquery/Kendo/styles/kendo.default.css" rel="stylesheet"/>
   
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
  
    <script src="/Jquery/Kendo/js/jquery.min.js" type="text/javascript"></script>
    <script src="/Jquery/Kendo/js/Kendo.all.min.js" type="text/javascript"></script>
    <script src="/Jquery/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
  
  
   
    <script type="text/javascript">

  
    $(function()
    {
    $("#txtFrom").kendoAutoComplete(
    {
        minLength: 3,
        filter: 'contains',
        severFiltering: true,
        serverPaging: true,
dataTextField: "CodAirport", 
        dataSource:
        new kendo.data.DataSource(
            {
            type: "json",
            transport: {
            read: "/Search/GetAirport.aspx",
                parameterMap: function() {
                return {
                apt: $("#txtFrom").data("kendoAutoComplete").value()
                    };
                }
 
            }
                 
            })
     });

 })
    </script>
<body>

    <form id="form1" runat="server">
    <div>
    <asp:TextBox runat="server" ID="txtFrom"   Width="220px" />
    </div>
    </form>

</body>
</html>

the sistme send me this error :

function anonymous(d, __f, __o) {
return (d.CodAirport.toLowerCase().indexOf('lin') >= 0)
}

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 29 Feb 2012, 05:03 AM
I'm having the same problem and it seems to be because the JSON returned from the server is still in unparsed string form when it gets to the error location indicated in the post. I've managed to get around this by parsing the raw data as JSON in the schema.data method:

               schema: {
                  data: function (data)
                  {
                     // TODO: should already be parsed as JSON at this point, I think
                     return $.parseJSON(data).table.rows;
                  }
               },

but it seems like I shouldn't have to do this?

Cheers, Andrew.
Tags
AutoComplete
Asked by
Alessandro
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or