AJAX REST Call

View Source to copy/examine the source

Using openweathermap.com API


Get Weather Data


    $(document).ready(function() {

        $('#btnGetWeather').click(function() {
            var requestData = $('#txtCity').val() + ',' + $('#txtCountry').val();
            var resultElement = $('#resultDiv');
            var APPIDkey = '5aa77646559bbd120a169ce6eefebd55';
            $.ajax({
                url: 'http://api.openweathermap.org/data/2.5/weather?units=imperial&',
                method: 'GET',
                data: {
                    q: requestData,
                    APPID: APPIDkey
                },
                dataType: 'JSON',
                success: function(data) {
                    resultElement.html('Map: ' + data.coord.lon +
                        ' longitude / ' + data.coord.lat +
                        ' latitude
Conditions: ' + data.weather[0] .main + '
Temperature: ' + data.main.temp + ' degrees F (high of: ' + data.main.temp_max + ' with a low of: ' + data.main.temp_min + ')
Wind: ' + data.wind.speed + ' miles/hr
Humidity: ' + data.main .humidity + '%'); } }); }); });
"/rest.txt";