Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431072
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:16:52+00:00 2026-05-18T07:16:52+00:00

I’m looking at this jQuery Autocomplete example . What I can’t figure out is

  • 0

I’m looking at this jQuery Autocomplete example.

What I can’t figure out is how much of this code depends on the structure of the returned JSON data.

For example, there is a line below:

name_startsWith: request.term

Is name_startsWith a function defined somewhere else or an implicit function of some kind?

What is reqest.term that it refers to? I can’t find the text term referred to anywhere else in the html document.

I want to try substituting my own JSON url into the example to see if it works but I don’t know how much of the example needs to change based on the structure of the JSON response data.

    <script> 
    $(function() {
        function log( message ) {
            $( "<div/>" ).text( message ).prependTo( "#log" );
            $( "#log" ).attr( "scrollTop", 0 );
        }

        $( "#city" ).autocomplete({
            source: function( request, response ) {
                $.ajax({
                    url: "http://ws.geonames.org/searchJSON",
                    dataType: "jsonp",
                    data: {
                        featureClass: "P",
                        style: "full",
                        maxRows: 12,
                        name_startsWith: request.term
                    },
                    success: function( data ) {
                        response( $.map( data.geonames, function( item ) {
                            return {
                                label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                value: item.name
                            }
                        }));
                    }
                });
            },
            minLength: 2,
            select: function( event, ui ) {
                log( ui.item ?
                    "Selected: " + ui.item.label :
                    "Nothing selected, input was " + this.value);
            },
            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> 

<div class="demo"> 

<div class="ui-widget"> 
    <label for="city">Your city: </label> 
    <input id="city" /> 
    Powered by <a href="http://geonames.org">geonames.org</a> 
</div> 

<div class="ui-widget" style="margin-top:2em; font-family:Arial"> 
    Result:
    <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> 
</div> 

</div><!-- End demo --> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:16:53+00:00Added an answer on May 18, 2026 at 7:16 am

    The data parameter is just a POJO (Plain Old Javascript Object) that gets serialized into a JSON string and sent as a collection of parameters to the server.

    In essence, you’re posting 4 parameters: featureClass, style, maxRows and name_startsWith with the values "p", "full", 12 and the value of request.term (which is supplied through the request parameter by the autocomplete widget, I believe).

    The server then processes the parameters it gets from the client and returns another JSON string, this time containing the following object:

    jsonp1290623850128({
        "totalResultsCount": 55,
        "geonames": [{
            "countryName": "Indonesia",
            "adminCode1": "30",
            "fclName": "city, village,...",
            "score": 19.488441467285156,
            "countryCode": "ID",
            "lng": 106.4183333,
            "adminName2": "",
            "adminName3": "",
            "fcodeName": "populated place",
            "adminName4": "",
            "timezone": {
                "dstOffset": 7,
                "gmtOffset": 7,
                "timeZoneId": "Asia/Jakarta"
            },
            "toponymName": "Test",
            "fcl": "P",
            "continentCode": "AS",
            "name": "Test",
            "fcode": "PPL",
            "geonameId": 1959830,
            "lat": -6.1052778,
            "adminName1": "West Java",
            "population": 0
        },
        {
            "alternateNames": [{
                "name": "http://en.wikipedia.org/wiki/Pomerode",
                "lang": "link"
            }],
            "countryName": "Brazil",
            "adminCode1": "26",
            "fclName": "city, village,...",
            "score": 18.81304168701172,
            "countryCode": "BR",
            "lng": -49.17694444,
            "adminName2": "",
            "adminName3": "",
            "fcodeName": "populated place",
            "adminName4": "",
            "timezone": {
                "dstOffset": -3,
                "gmtOffset": -2,
                "timeZoneId": "America/Sao_Paulo"
            },
            "toponymName": "Testo",
            "fcl": "P",
            "continentCode": "SA",
            "name": "Testo",
            "fcode": "PPL",
            "geonameId": 3453245,
            "lat": -26.74055556,
            "adminName1": "Santa Catarina",
            "population": 21898
        },
        // ---- [snip] ----
        {
            "countryName": "Turkey",
            "adminCode1": "23",
            "fclName": "city, village,...",
            "score": 13.442560195922852,
            "countryCode": "TR",
            "lng": 39.126705,
            "adminName2": "",
            "adminName3": "",
            "fcodeName": "populated place",
            "adminName4": "",
            "timezone": {
                "dstOffset": 3,
                "gmtOffset": 2,
                "timeZoneId": "Europe/Istanbul"
            },
            "toponymName": "Testek",
            "fcl": "P",
            "continentCode": "AS",
            "name": "Testek",
            "fcode": "PPL",
            "geonameId": 299236,
            "lat": 38.458786,
            "adminName1": "Elazığ",
            "population": 0
        }]
    });
    

    This is basically an object with two properties: totalResultsCount, containing the number of results as an integer, and geonames that contains an array of result objects that carry specific properties, like countryName, name, population, etc.

    This JSON object gets consumed in the success function inside the $.ajax() function, where you can iterate over the individual objects:

    for(var i = 0; i < data.geonames.length; i++) {
      var current = data.geonames[i]; // the current object
    }
    

    The map function in your example simply converts each result into a new object (containing label and value properties) and collects them into an array that gets passed into the response function (passed into your AJAX call by the widget).

    So, to answer your question, if you simply want to change the URL, the service needs to answer with the same JSON structure as the one I pasted. If not, you can change the success function to match the JSON structure that your service returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.