问题描述
本 Request.JSON
检索国家code
和 CountryFlags
通过的其中xx是2 ISO国家code
I'm looking for a method to use Geonames
via http://api.geonames.org/export/geonamesData.js?username=orakzai to retrieve Countrycode
and CountryFlags
via http://www.geonames.org/flags/x/xx.gif where xx is 2 letter ISO country code
推荐答案
这些标志返回GIF文件,而不是任何形式的JSON的。你只需使用
The flags are returned as GIF files instead of any sort of JSON. You would just use
<img id='myImage' src="http://www.geonames.org/flags/x/??.gif" />
但填写?与GEONAMES使用国家code。
But fill in the ?? with the country code that geonames uses.
您可以把标签在你的页面的某个地方,并使用一些JavaScript的URL更改为您所计算的一个或可以计算服务器上的URL,并把它作为创建的HTML页面。
You can put the tag in your page somewhere and use some javascript to change the URL to the one you have computed or you can figure the URL on your server and insert it as the HTML page is created.
如果你想这样做在JavaScript中,例如,在jQuery的你会像这样使用id =MYIMAGE'来改变已加载的图像标记的URL
If you want to do it in javascript, for example, in jQuery you would have something like this to change the URL on an already loaded image tag with id='myImage'
$("#myImage").attr('src', "http://www.geonames.org/flags/x/" + countryCode + ".gif")
这篇关于使用JSONP技术的负荷国家国旗从国地名API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!