Javascript 我是否正确设置了此天气应用程序的API?

Javascript 我是否正确设置了此天气应用程序的API?,javascript,html,json,Javascript,Html,Json,我正在使用天气应用程序api,并试图根据用户在表单中插入的内容显示天气数据。由于某些原因,数据未显示。我已经把代码看了10遍,但似乎找不到错误 有人能看一下我的错误吗 多谢各位 $(文档).ready(函数(){ $('submitWeather')。单击(函数(){ var city=$('#city').val(); 如果(城市!=''){ $.ajax({ 网址:'https://api.openweathermap.org/data/2.5/weather?q=“+city+”&uni

我正在使用天气应用程序api,并试图根据用户在表单中插入的内容显示天气数据。由于某些原因,数据未显示。我已经把代码看了10遍,但似乎找不到错误

有人能看一下我的错误吗

多谢各位

$(文档).ready(函数(){
$('submitWeather')。单击(函数(){
var city=$('#city').val();
如果(城市!=''){
$.ajax({
网址:'https://api.openweathermap.org/data/2.5/weather?q=“+city+”&units=metric“+”&APPID=\u MY\u API\u KEY\u”,
键入:“获取”,
数据类型:“jsonp”,
成功:功能(数据){
var widget=show(数据);
$(“#show”).html(小部件);
$(“#城市”).val(“”);
}
});
}否则{
$(“#error”).html('字段不能为空');
}
});
});
功能显示(数据){
返回“Weather:”+data.Weather[0].main+'+
“天气”:“+data.Weather[0].说明+”;
}
console.log('hello')
.main区域{
背景颜色:浅灰色;
}
.第1天,
.第2天,
.第3天,
.第4天,
.第5天{
宽度:220px;
高度:200px;
背景颜色:蓝色;
位置:相对位置;
颜色:白色;
}
.输入{
文本对齐:居中;
}
输入[type='text']{
高度:50px;
宽度:200px;
背景:#e7e7e7;
}
输入[type='submit']{
高度:50px;
宽度:100px;
背景:蓝色;
}

天气仪表盘
天气预报
输入城市名称
搜寻

$('submitWeather')应该是$('submitWeather')

$('submitWeather')应该是$('submitWeather')

以下是在没有jquery的情况下如何做的,以防任何人想要它:

const getCity=()=>document.querySelector('input#city')。value | |“austin”
document.querySelector(“#getWeather”).addEventListener('click',函数(){
常量url=`https://api.openweathermap.org/data/2.5/weather?q=${getCity()}&units=metric&APPID=\u MY\u API\u KEY_`
loadDataRequest(url、displayJSON)
})
函数loadDataRequest(url,cb){
var-xhttp;
xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
cb(本);
}
};
xhttp.open(“GET”,url,true);
xhttp.send();
}
函数displayJSON(xhttp){
document.querySelector(“#show”).textContent=JSON.stringify(JSON.parse(xhttp.response),null,2);
}

得到

以下是在没有jquery的情况下如何做到这一点,以防任何人需要它:

const getCity=()=>document.querySelector('input#city')。value | |“austin”
document.querySelector(“#getWeather”).addEventListener('click',函数(){
常量url=`https://api.openweathermap.org/data/2.5/weather?q=${getCity()}&units=metric&APPID=\u MY\u API\u KEY_`
loadDataRequest(url、displayJSON)
})
函数loadDataRequest(url,cb){
var-xhttp;
xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
cb(本);
}
};
xhttp.open(“GET”,url,true);
xhttp.send();
}
函数displayJSON(xhttp){
document.querySelector(“#show”).textContent=JSON.stringify(JSON.parse(xhttp.response),null,2);
}

得到

您似乎发布了敏感/私人信息。请重置您的密码和/或撤销API密钥和令牌,因为这些密钥和令牌在发布到internet上时被视为已被泄露。如果发布了可识别个人身份的信息,请删除该信息,然后标记您的帖子,以便版主对之前的修订进行修订。您似乎发布了敏感/私人信息。请重置您的密码和/或撤销API密钥和令牌,因为这些密钥和令牌在发布到internet上时被视为已被泄露。如果发布了可识别个人身份的信息,请将该信息标记出来,然后由版主编辑先前的修订。非常欢迎:)我可以要求你接受答案吗?非常欢迎:)我可以要求你接受答案吗?