I am using Getty Image Photo Search API and I would like the images returned to represent the phrased search. Here is all of my code below. When I put say "NASA" as the endpoint it works, but I would like for it to be what the user inputs.
var apiKey = 'apiKey';
var item = document.getElementById("item");
$.ajax({
type: 'GET',
url: "https://api.gettyimages.com/v3/search/images/creative?phrase=+item",
beforeSend: function(request) {
request.setRequestHeader("Api-Key", apiKey);
}
})
.done(function(data) {
console.log("Success with data")
for (var i = 0; i < data.images.length; i++) {
$("#output").append("<img src='" + data.images[i].display_sizes[0].uri + "'/>");
}
})
.fail(function(data) {
alert(JSON.stringify(data, 2))
});
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="places.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>
<form class="form-inline" action="" method="post">
<div class="form-group">
<input type="text" class="form-control " id="item" name="imageSearch" placeholder="Search for an Image">
</div>
<input class="btn btn-default" type="submit" value="Submit">
<br>
<br>
</form>
<div id="output"></div>
</body>
</html>