-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (34 loc) · 981 Bytes
/
Copy pathapp.js
File metadata and controls
43 lines (34 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Movie poster getter from OMDB API
// event listener to send data from form to OMDB API
$( document ).ready(function(){
myapp = new App();
myapp.addEventListener();
});
function App(){
this.$searchButton = $('#searchButton');
this.$searchInput = $('#searchInput');
this.$posterContainer = $('#posterContainer');
}
App.prototype.addEventListener = function(){
var app = this;
this.$searchButton.click( function(){
app.sendQuery(event);
});
};
App.prototype.sendQuery = function() {
event.preventDefault();
var searchInput = this.$searchInput.val();
this.makeAjaxCall(searchInput)
};
App.prototype.makeAjaxCall = function(searchInput){
var app = this;
$.ajax({
url: "http://www.omdbapi.com/?t="+ searchInput +"&y=&plot=short&r=json",
}).done(function(data) {
app.addPosterToPage(data.Poster)
});
};
App.prototype.addPosterToPage = function(poster){
this.$posterContainer.html("<img src=" + poster + ">")
}
// data.Poster