Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>data</code> 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.</p> <p>In essence, you're posting 4 parameters: <code>featureClass</code>, <code>style</code>, <code>maxRows</code> and <code>name_startsWith</code> with the values <code>"p"</code>, <code>"full"</code>, <code>12</code> and the value of <code>request.term</code> (which is supplied through the <code>request</code> parameter by the autocomplete widget, I believe).</p> <p>The server then processes the parameters it gets from the client and returns another JSON string, this time containing the following object:</p> <pre><code>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 }] }); </code></pre> <p>This is basically an object with two properties: <code>totalResultsCount</code>, containing the number of results as an integer, and <code>geonames</code> that contains an array of result objects that carry specific properties, like <code>countryName</code>, <code>name</code>, <code>population</code>, etc.</p> <p>This JSON object gets consumed in the <code>success</code> function inside the <code>$.ajax()</code> function, where you can iterate over the individual objects:</p> <pre><code>for(var i = 0; i &lt; data.geonames.length; i++) { var current = data.geonames[i]; // the current object } </code></pre> <p>The map function in your example simply converts each result into a new object (containing <code>label</code> and <code>value</code> properties) and collects them into an array that gets passed into the <code>response</code> function (passed into your AJAX call by the widget).</p> <p>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 <code>success</code> function to match the JSON structure that your service returns.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload