Created
January 19, 2015 13:46
-
-
Save fizerkhan/4b89013581bc9596a0a0 to your computer and use it in GitHub Desktop.
Get information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <script src="https://code.jquery.com/jquery-2.1.3.js"></script> | |
| </head> | |
| <body> | |
| <h2>Select the City:</h2> | |
| <form id="myForm" name="myForm" action=""> | |
| <select name="" id="city"> | |
| <option value="Los_Angeles" selected>Los Angels</option> | |
| <option value="newyork">New York</option> | |
| <option value=""></option> | |
| </select> | |
| <button type="submit">Submit</button> | |
| </form> | |
| <br> | |
| <hr> | |
| <h2>Information:</h2> | |
| <span id="loading" style="display:none">Loading...Please wait</span> | |
| <p><strong>Population Total: </strong> <span id="pop-total"></span></p> | |
| <p><strong>Population Density: </strong> <span id="pop-den"></span></p> | |
| <p><strong>Area Total: </strong> <span id="area-total"></span></p> | |
| <script> | |
| $('#myForm').submit(function () { | |
| var city = $('#city').val(); | |
| $('#pop-total').html(''); | |
| $('#pop-den').html(''); | |
| $('#area-total').html(''); | |
| $('#loading').show(); | |
| $.ajax({ | |
| contentType: "application/json; charset=utf-8", | |
| url: 'http://dbpedia.org/data/Los_Angeles.json', | |
| dataType: "json", | |
| success: function(data) { | |
| var populationTotal = data['http://dbpedia.org/resource/Los_Angeles']['http://dbpedia.org/ontology/populationTotal'][0]['value']; | |
| $('#pop-total').html(populationTotal); | |
| var populationDensity = data['http://dbpedia.org/resource/Los_Angeles']['http://dbpedia.org/ontology/populationDensity'][0]['value']; | |
| $('#pop-den').html(populationDensity); | |
| var areaTotal = data['http://dbpedia.org/resource/Los_Angeles']['http://dbpedia.org/ontology/areaTotal'][0]['value']; | |
| $('#area-total').html(areaTotal); | |
| $('#loading').hide(); | |
| }, | |
| error: function () { | |
| $('#loading').hide(); | |
| alert('Sorry, some error occurs') | |
| } | |
| }); | |
| return false; | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment