Calling live json web service using jquery ajax

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

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.

Here is the HTML and jQuery code used in the demo

<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
$('#btnGetWeather').click(function () {
var resultElement = $('#resultDiv');

var requestData = $('#txtCity').val() + ',' + $('#txtCountry').val();
$.ajax({
method: 'get',
data: { q: requestData },
dataType: 'json',
success: function (response) {
}
else {
}
},
error: function (err) {
alert(err);
}
});
});
});
</script>
</head>
<body style="font-family:Arial">
<table>
<tr>
<td>City</td>
<td><input type="text" id="txtCity" /></td>
</tr>
<tr>
<td>Country</td>
<td><input type="text" id="txtCountry" /></td>
</tr>
</table>
<input type="button" id="btnGetWeather" value="Get Weather Data">
<br /><br />
<div id="resultDiv">
</div>
</body>
</html>
Рекомендации по теме
Комментарии
Автор

Thank you so much. This really made my day.

Kajerman
Автор

Thank you, I really loved your simple, understandable presentation.. LIKE!!!

mahlatsetshehla
Автор

Its a amazing ..superb I like your all videos . and thanks for your support

umeshagrawal
Автор

Thankyou So much sir.. We are fortunate to have you :)

iHamzaKhanzada
Автор

I have one doubt. If you are not Posting any data to that web service why have you created data: { q : requestdata }. In few tuts, i have heard that in GET request data should not be present. Confused?

gauranglondhe
Автор

i am not getting the output for this program?
May i know the reason

lakshmipriya
Автор

Hello, I tried calling .asmx web service on running on IIS manager using jquery but its result in error. Is it possible? let me possible solution

niveditamunj
Автор

An API key is needed to access weather information but I don't know how to use it. @Kunal mentioned maybe needing to include it in the query string but you didn't use one in the jQuery function you wrote. What do I do?

lharr
Автор

i ned to include this javascript jquery-1.11.2.js else it will not work why so ??

pankajjadhav
Автор

Sir, For which organisation you are working?

rajpandey-jljl
Автор

Hey nice tutorial i am not getting json data at the end i followed same as you did

muhammedmehraj
Автор

Great video, really nicely done. Everything worked for me except handling and displaying the 'Error: Not found city'. Should I be using something other than data.message != null ?

RMalcolmXL
Автор

How do I decide whether weather?q= or weather?p=. How do I know if I am require

jeyosman
Автор

I am unable to get value in data.weather[0].main and description. I have error there . Weather is undefined

pooja_sri
Автор

how to call a web service using javascript and not jquery ajax?

gauranglondhe
Автор

I do every step + i copy the whole file. Nothing happend when i press in London and UK get weather data.Not sure what i do wrong here.

MrKoenBE
Автор

Hey I want it in c# not in html and I want to parse d json data then display I want to displya in web page

snehakawale
Автор

If you have APPID key problems, do this:

var APPIDkey = (this is my key, you will get yours when you sign up)

In "data" part of ajaxs just add:

data: { q: requestData, APPID: APPIDkey },

braScene
Автор

PROBLEM RESOLVED!!

get the apid key and use this syntax

$.ajax({
method: 'GET',
data: {q: data1, appid: appid},
dataType: 'JSON',
success: function(data){
dataBack.html('weather:' + data.weather[0].main + '<br/>' +
'Description:' + data.weather[0].description);
}
});

pukka
Автор

HELP NEEDED!!
DATA RETURN FROM THE SERVER
{
"error_msg": {
"title": "<p>The Book title field is required.</p>",
"authors_name": "<p>The Author's name field is required.</p>",
"source": "<p>The Source field is required.</p>"
}
}
END OF JSON DATA

AJAX SUCCESS FUNCTION
success: function(data) {
console.log(data);
}

END OF AJAX SUCCESS FUNCTION

I want to show only title in console. Please help me how to show this particular element.
I already tried it as follows-
console.log(data.title);

entertainmentmedia