Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Calling live json web service using jquery ajax

Suggested Videos
Part 68 - How to call wcf service using jquery
Part 69 - Difference between window height and document height
Part 70 - Load data on page scroll using jquery

In this video we will discuss how to call a live weather web service that returns JSON data using jquery ajax.

For the purpose of this demo, we will be using the live weather web service that returns JSON data. The web service can be found at the following URL.

We want to retrieve weather data from the web service and display it on a web page as shown below.


Here is the HTML and jQuery code used in the demo

    <script src="jquery-1.11.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnGetWeather').click(function () {
                var resultElement = $('#resultDiv');

                var requestData = $('#txtCity').val() + ',' + $('#txtCountry').val();
                    url: '',
                    method: 'get',
                    data: { q: requestData },
                    dataType: 'json',
                    success: function (response) {
                        if (response.message != null) {
                        else {
                            resultElement.html('Weather: ' +[0].main + '<br/>'
                                + 'Description: ' +[0].description);
                    error: function (err) {
<body style="font-family:Arial">
            <td><input type="text" id="txtCity" /></td>
            <td><input type="text" id="txtCountry" /></td>
    <input type="button" id="btnGetWeather" value="Get Weather Data">
    <br /><br />
    <div id="resultDiv">

jQuery tutorial for beginners


  1. Hi. I was watiching your video in youtube, I tried to replicated the example in my computer, but I recived a message error from ajax and don't work. Could you give me any idea for try to fix my code. thanks.

  2. No data is displayed no api call , while debugging i got to found , a 401 unauthorized error is throwing. Can you please help

  3. data: { q: requestData, appid:'279398317b5b2ce08766828fb64d0e1c'},

    use that data property instead of data: { q: requestData},


If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.