<script>
var apikey = "someKey";
var SEid = "0137454dfgsdfgsdfgzxv4435099:pnqp_fvtmsy";
var query = "Flower";
var returnedData;
$.get("https://www.googleapis.com/customsearch/v1?key=" + apikey + "&cx=" + SEid + "&q=" + query, function(data){
console.log(data);
returnedData = data;
});
console.log(returnedData.items[1].formattedUrl);
</script>
I keep getting back the error Uncaught TypeError: Cannot read property 'items' of undefined
but I can't figure out why the variable returned Data is undefined. I'm not trying to even reference it until after I've called the get request.
Please don't flag this question as invalid, I'm really trying to figure this out and have tried for the past 2 days various methods but I just can't figure it out.