$ .ajax不是函数 [英] $.ajax is not a function
问题描述
我正在尝试使用 Wunderground Weather API ,但是我在请求按钮单击信息时遇到了麻烦. 这是提供的工作开始线:
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($) {
这就是我将其更改为:
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);
}
});
});
推荐答案
click
事件不发送jQuery对象作为参数,而是发送event
对象,因此函数内部的$
t是jQuery对象,它将是click事件的event
对象.
The click
event doesn't send the jQuery object as parameter, it sends the event
object, so the $
inside the function won't be the jQuery object, it will be the event
object for the click event.
只需删除$
参数,以使其不会遮盖全局$
标识符:
Just remove the $
parameter so that it doesn't shadow the global $
identifier:
jQuery('#GetWeather').click(function() {
这篇关于$ .ajax不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!