我是jquery和ajax的新手,所以请原谅。无论如何,我正在尝试向谷歌地理编码api发送一个位置并收回一对坐标。但是,由于某种原因,我的功能将无法正常工作。我做错了什么,应该如何解决?
scripts.js中
function getData(address)
{
$.ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json',
crossDomain: true,
type: 'post',
data: {
'address': address,
'api' :
},
success: function (data) {
var results = data.results;
localStorage.setItem("hi",data.results);
alert(results);
return results;
}
});
}
function getAddress()
{
var address = document.getElementById('aa').value;
console.log(address);
localStorage.setItem("add", address);
window.location="weather.html";
var array = getData(localStorage.add);
console.log("hi");
}
if(window.location.pathname == "/home.html"){
document.getElementById("swag").onclick = getAddress
}
if(localStorage.add && window.location.pathname != "/weather.html"){
window.location="weather.html";
}