$ajax not. function,jquery - $.ajax is not a function - Stack Overflow

在尝试使用Wunderground天气API获取英国PL99UT地区的天气信息时,遇到点击按钮后触发AJAX请求失败的问题。错误信息显示$.ajax不是一个函数。代码中设置了一个点击事件处理函数,当点击 '#GetWeather' 按钮时,应发送JSONP请求获取天气数据,但似乎jQuery库没有正确加载或使用方式有误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hi i am trying to use Wunderground Weather API but i am having troubles with requesting the information on a button click.

Here is the working opening line Supplied:

jQuery(document).ready(function($) {

And here is what i changed it to:

jQuery('#GetWeather').click(function($) {

When i click the button i get a firebug Error:

TypeError: $.ajax is not a function

[Break On This Error]

success : function(parsed_json) {

I don't know why it wont work but here is the rest of the code... Hope it helps:

jQuery('#GetWeather').click(function($) {

var PostCode="PL9 9UT";

$.ajax({ url : "http://api.wunderground.com/api/2508132ae0c7601a/geolookup/conditions/q/UK/"+PostCode +".json",

dataType : "jsonp",

success : function(parsed_json) {

var icon = parsed_json['current_observation']['icon'];

var temp_c = parsed_json['current_observation']['temp_c'];

var feelslike_c = parsed_json['current_observation']['feelslike_c'];

var visibility_mi = parsed_json['current_observation']['visibility_mi'];

var UV = parsed_json['current_observation']['UV'];

var relative_humidity = parsed_json['current_observation']['relative_humidity'];

var wind_mph = parsed_json['current_observation']['wind_mph'];

var pressure_mb = parsed_json['current_observation']['pressure_mb'];

var wind_string = parsed_json['current_observation']['wind_string'];

var weather = parsed_json['current_observation']['weather'];

var imageurl = "http://192.168.0.4/DesktopVersion/Inc/Images/Weather/";

$('.Wicon').css('background-image',"url("+imageurl +icon +".svg)");

$('#GetWeatherTemp').html(temp_c +"°");

$('#GetWeatherFeel').html("Feels Like " +feelslike_c +"℃");

$('#GetWeatherVis').html(visibility_mi +" Miles");

$('#GetWeatherUv').html(UV);

$('#GetWeatherHumid').html(relative_humidity +"%");

$('#GetWeatherWind').html("Wind Speed " +wind_mph +"Mph");

$('#GetWeatherPress').html(pressure_mb);

$('#GetWeatherState').html(weather);

}

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值