I am super new to jquery and ajax, so please excuse me. Anyways, I am trying to send a location to the google geocoding api and receive back a pair of coordinates. However, for some reason my function won't work. What am I doing wrong and how should i fix it?
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";
}