以下代码无效。请检查并提供可能的解决方案
{
("button").click(function(){
var scity =$("input:text").val();
alert (scity);
});
$.ajax({
type: "GET",
url: "http://api.openweathermap.org/data/2.5/weather?mode=xml&q="+scity+",
dataType: "xml",
success:parseXML});
});
}
i try to enter the value of city in url. but its not working.
答案 0 :(得分:0)
您是否注意到控制台中记录了任何错误?
您有输入错误,但我不确定您发布的代码是否与您正在使用的代码完全相同。如果是,请尝试在AJAX调用的url属性中删除+"
之后的scity
。另外,尝试将var scity
移出点击功能。像这样:
var scity;
$("button").click(function() {
scity = $("input:text").val();
alert(scity);
});
$.ajax({
type: "GET",
url: "http://api.openweathermap.org/data/2.5/weather?mode=xml&q=" + scity,
dataType: "xml",
success: parseXML
});