Tuesday, April 7, 2015

jQuery - Populating a dropdown list in JSONP format

Here's a quick example of how to retrieve JSONP data from a 3rd party site via AJAX and bind it to an HTML select control.

This example relies on jQuery and uses mysafeinfo.com to retrieve U.S. States data in JSONP format. MySafeInfo is a free service we offer to software developers to provide test data in a simple, flexible manner, in a variety of formats.

Also, the example above is using $.getJSON and retrieving JSONP data; however, it could just as easily retrieve standard JSON data, or for that matter could retrieve data in another format such as XML, for example: