I am getting a successful response back, but I do not fully understand how to loop through the data I get back. I put in an alert in the success callback, but that wasn’t called. Here is the markup and script:
<input type="text" name="searchValue" id="searchValue"/>
<input type="button" name="btnGetLicenes" value="Get Licenses" id="btnGetLicenses"/>
<div id="Licenses"></div>
<script>
$.getJSON("http://data.fcc.gov/api/license-view/basicSearch/getLicenses?searchValue=Verizon Wireless&format=jsonp&callback=?",
function (data) {
$.each(data.License, function (i, lic) {
$('#Licenses').append('<p>' + lic.licName + '</p>');
alert("hello"); //This is not called.
});
});
</script>
In the above scenario, I am not using the search text box, I just hard-coded Verizon Wireless for testing.
You have an intermediary
data.Licenses.Licensenode which represents the collection you can loop through:Also
$alertis not a function that you can expect to be called. Maybe you meantalert.Also notice that according to the documentation the parameter that allows you to set the JSONP callback name is
jsonCallback, notcallbackas in your example.Also don’t forget to URL encode your query string parameters or you might get unexpected/wrong behavior from the server:
searchValue=Verizon Wirelessshould besearchValue=Verizon+Wireless.And finally here’s a live demo to see this in action.