Please help me I am new to ajax calling from json, I could get the data from json, please look from below code.
Can we call from local server how its worked,
Please give bit clear picture
In chrome console error :
XMLHttpRequest cannot load http://api.openweathermap.org/data/2.5/weather?q=%2C. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8012' is therefore not allowed access. The response had HTTP status code 401.
code:
 <!DOCTYPE html>
    <html>
    <script src="http://localhost:8012/js/jquery.min.js"></script>
    <body>
    <div> city : <input type="text" id="txtCity"></div><br/>
    <div> Country : <input type="text" id="txtCountry"></div><br/>
    <input type="button" value="Get weather" id="getWeather">
    <div id="#resultDiv"></div>
    <script>
        $(document).ready(function() {
        $("#getWeather").click(function() {
            var requestData = $("#txtCity").val() + ',' + $("#txtCountry").val();
            var resultElement = $("#resultDiv");
                $.ajax({
                        url: 'http://api.openweathermap.org/data/2.5/weather',
                        method: 'get',
                        data: {
                            q: requestData
                        },
                        dataType: 'json',
                        success: function(data) {
                            resultElement.html('weather: ' + data.weather[0].main + '<br/>' +
                                'Description: ' + data.weather[0].description);
                    }
                });
    //alert("test");
        });
    });
    </script>
    </body>
    </html>
 
     
    