I've been working on a simple webpage that allows users to enter the name of a city in a text box and then displays basic information about it, such as the address and name. My main issue right now is with the Google Places API. Below is what I have managed to put together so far:
restaurants.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Restaurant Search</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery.js"></script>
<script src="functions.js"></script>
<script>
$(document).ready(function(){
getRestaurants();
});
</script>
</head>
<body>
<div class="main">
<form>
Enter city name: <input id="city" type="text" name="cityname"><input id="btn" type="submit" value="Search">
</form>
<div id="error">
The search field cannot be left empty!
</div>
</div>
<div id="header">
</div>
<div id="items">
</div>
</body>
</html>
functions.js
function getRestaurants(){
$("#btn").click(function(){
if ($("#city").val().length==0){
$("#error").css("display","block");
}else{
$("#error").css("display","none");
var cityname = $("#city").val();
var search_string = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+"+cityname+"&sensor=false&key=KEYKEYKEY";
$.ajax({
url: search_string
}).done( function ( data ) {
res ="";
var obj = jQuery.parseJSON(data);
$(obj).each(function(){
res+=this.name;
});
$("#items").text(res);
});
}
});
}
style.css contains only this:
#error{
display: none;
}
Can you spot the problem?