html - how to handle json data in javascript -
i using worldweatheronline api access weather data,when request send response sending data in json.i want display weather information in html page
<!doctype html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head> <body> <input type="text" id="in"></input> <input type="hidden" id="keys" value="apikey"></input> <button id="go">search</button> <script> $(document).ready(function(){ $("#go").click(function(){ var apikey = $("#keys").val(); var q = $("#in").val(); jquery.ajax({ url: 'http://api.openweathermap.org/data/2.5/weather?key=' + apikey + '&q=' + q, success: function(response){ var obj = json.parse(response); console.log(obj); }, }); }); }); </script> </body> </html> <html> <head> <title>weather app</title> </head> <body> <form method="get" action="http://api.openweathermap.org/data/2.5/weather"> <input type="hidden" name="key" value="apikeyneeded"></input> <input type="text" name="q"></input> </form> </body> </html>
check this.
var apikey = jquery('[name="key"]').val(); var q= jquery('[name="q"]').val(); jquery.ajax({ url: 'http://api.openweathermap.org/data/2.5/weather?key=' + apikey + '&q=' + q, success: function(response){ var obj = json.parse(response); console.log(obj); }, }); add line head tag include jquery <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
Comments
Post a Comment