Tuesday 15 February 2011

javascript - Modifying JSON Ajax Request for Geonames -


I have code after an example site, but I was wondering if someone could tell me how to modify the code below To return results from the United States only

This is the code so far:

  $ (function () {function log (message) {$ (" & Lt; div & gt; ") .text message ()) .prependTo (" #log "); $ ("#log") .scrollTop (0);} $ ("#city"). Autocomplete ({source: function (request, response) {$ .ajax ({Url: "http://ws.geonames.org/searchJSON", data type: "jsonp", data: {featureclass: "P", style : "Full", maxrows: 12, name_startsWith: request.term}, success: function (data) {response ($ .map (data.jonomes, function (item) {returns {label: item.name + (item.adminname I }}}}}}}}, Select the MinNamban: 2,: Function (Event, UI) None selected, input "+ this.value"}}, open: function () {$ .removeClass ("ui-corner-all"). AddClass ("ui-corner-top");}, close: function () {$ (this) .removeClass ("ui-corner-top") .addClass ("ui-corner-all");}});});   

Apparently you can request JSON in this way:

  http://ws.geonames.org/searchJSON?name_startsWith=Chic& ; Country = US   

So my question is, how do I modify the above code to include "& amp; country = US" on request? I have tried some things, but it completely breaks the request

Country parameters on data variables Keep:

  Data: {Featureclass: "P", Style: "Full", Max: 12, Name_Start: request.term, Country: "US"},   

So simple!

In this case, the data variable is used to construct the QuickString of a Ajax request.

No comments:

Post a Comment