使用JSONP技术的负荷国家国旗从国地名API [英] Load Country Flag From Geonames API using JSONP technique

查看:1090
本文介绍了使用JSONP技术的负荷国家国旗从国地名API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Request.JSON http://mootools.net在这样的方式,

This Request.JSON http://mootools.net/demos/?demo=Request.JSON using JSON data in a way like this,

var data = {"previews":[
  {"Countrycode":"us", "src":"us.jpg", "description":"desc will be here"},
  {"Countrycode":"uk", "src":"uk.jpg", "description":"desc will be here"},
]};

在我们使用国家code &功放上面的方法; 图片通过写入每个图像的名称我们的自我。

In the above method we use Countrycode & images by writing name of each image our self.

我在寻找一种方法来通过<一个使用国地名 href=\"http://api.geonames.org/export/geonamesData.js?username=orakzai\">http://api.geonames.org/export/geonamesData.js?username=orakzai检索国家code CountryFlags 通过的http://www.geonames.org/flags/x/xx.gif 其中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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆