Fetching movie data using jQuery The 2019 Stack Overflow Developer Survey Results Are...
How to manage monthly salary
Delete all lines which don't have n characters before delimiter
Origin of "cooter" meaning "vagina"
Is this app Icon Browser Safe/Legit?
Can you compress metal and what would be the consequences?
When should I buy a clipper card after flying to OAK?
What is the motivation for a law requiring 2 parties to consent for recording a conversation
Why not take a picture of a closer black hole?
What do hard-Brexiteers want with respect to the Irish border?
Did 3000BC Egyptians use meteoric iron weapons?
Is an up-to-date browser secure on an out-of-date OS?
Output the Arecibo Message
How to save as into a customized destination on macOS?
Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?
Right tool to dig six foot holes?
Falsification in Math vs Science
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Why was M87 targetted for the Event Horizon Telescope instead of Sagittarius A*?
Why is the Constellation's nose gear so long?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
Who coined the term "madman theory"?
How to support a colleague who finds meetings extremely tiring?
What is the most effective way of iterating a std::vector and why?
Why did Acorn's A3000 have red function keys?
Fetching movie data using jQuery
The 2019 Stack Overflow Developer Survey Results Are InFetching data via jquery and adding items to a listAJAX alternative of using jQuery form UIWrapper for jquery ajax to ensure redirects occur on clientsidejQuery AJAX form using bad practicePopulating many fields in a form using jQuery/AJAXFetching data from nested JSON using jQuery and displaying in tableSession expiration handler using PHP and jQueryCreating keyboard shortcuts for highlighting elements of given classes and toggle through themjQuery AJAX submit formNotification system using PHP+jQuery+Ajax
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Requirements
- Display movie datas inside all tags that have the class movie_list
- Make an ajax call for fetching movie datas
- Fill loading text before fetch data
- If any error occurs during loading, the content should be empty
What I did
- Cached all elements which have the class movie_list
- Made functions which have only one responsibility
- Functions take movieList elements for making easy to unit test
What I want to know
- More readable/reusable code
- Any performance improvement point
- Any good design pattern on here
function loadMovies() {
const url = 'http://moviedatas.com/movies';
const movieList = $('.movie_list');
setOnLoading(movieList);
$.ajax({
method: 'GET',
url: url,
data: {
count: 10
},
success: function(response) {
movieList.each(function() {
const wrapper = $(this);
render(wrapper, items);
});
},
error: function(error) {
onError(movieList);
}
})
}
function setOnLoading(movieList) {
movieList.each(function() {
$(this).html('Loading...');
});
}
function render(wrapper, items) {
const template = `<div class="movie_item">
<div class="title">{title}</div>
<div class="desc">{description}</div>
</div>`;
let movies = '';
for (let i = 0; i < items.length; i++) {
movies += template
.replace('{title}', items[i].title)
.replace('{description}', items[i].description);
}
wrapper.html(movies);
}
function onError(movieList) {
movieList.each(function() {
$(this).html('');
});
}
jquery ajax
New contributor
$endgroup$
add a comment |
$begingroup$
Requirements
- Display movie datas inside all tags that have the class movie_list
- Make an ajax call for fetching movie datas
- Fill loading text before fetch data
- If any error occurs during loading, the content should be empty
What I did
- Cached all elements which have the class movie_list
- Made functions which have only one responsibility
- Functions take movieList elements for making easy to unit test
What I want to know
- More readable/reusable code
- Any performance improvement point
- Any good design pattern on here
function loadMovies() {
const url = 'http://moviedatas.com/movies';
const movieList = $('.movie_list');
setOnLoading(movieList);
$.ajax({
method: 'GET',
url: url,
data: {
count: 10
},
success: function(response) {
movieList.each(function() {
const wrapper = $(this);
render(wrapper, items);
});
},
error: function(error) {
onError(movieList);
}
})
}
function setOnLoading(movieList) {
movieList.each(function() {
$(this).html('Loading...');
});
}
function render(wrapper, items) {
const template = `<div class="movie_item">
<div class="title">{title}</div>
<div class="desc">{description}</div>
</div>`;
let movies = '';
for (let i = 0; i < items.length; i++) {
movies += template
.replace('{title}', items[i].title)
.replace('{description}', items[i].description);
}
wrapper.html(movies);
}
function onError(movieList) {
movieList.each(function() {
$(this).html('');
});
}
jquery ajax
New contributor
$endgroup$
add a comment |
$begingroup$
Requirements
- Display movie datas inside all tags that have the class movie_list
- Make an ajax call for fetching movie datas
- Fill loading text before fetch data
- If any error occurs during loading, the content should be empty
What I did
- Cached all elements which have the class movie_list
- Made functions which have only one responsibility
- Functions take movieList elements for making easy to unit test
What I want to know
- More readable/reusable code
- Any performance improvement point
- Any good design pattern on here
function loadMovies() {
const url = 'http://moviedatas.com/movies';
const movieList = $('.movie_list');
setOnLoading(movieList);
$.ajax({
method: 'GET',
url: url,
data: {
count: 10
},
success: function(response) {
movieList.each(function() {
const wrapper = $(this);
render(wrapper, items);
});
},
error: function(error) {
onError(movieList);
}
})
}
function setOnLoading(movieList) {
movieList.each(function() {
$(this).html('Loading...');
});
}
function render(wrapper, items) {
const template = `<div class="movie_item">
<div class="title">{title}</div>
<div class="desc">{description}</div>
</div>`;
let movies = '';
for (let i = 0; i < items.length; i++) {
movies += template
.replace('{title}', items[i].title)
.replace('{description}', items[i].description);
}
wrapper.html(movies);
}
function onError(movieList) {
movieList.each(function() {
$(this).html('');
});
}
jquery ajax
New contributor
$endgroup$
Requirements
- Display movie datas inside all tags that have the class movie_list
- Make an ajax call for fetching movie datas
- Fill loading text before fetch data
- If any error occurs during loading, the content should be empty
What I did
- Cached all elements which have the class movie_list
- Made functions which have only one responsibility
- Functions take movieList elements for making easy to unit test
What I want to know
- More readable/reusable code
- Any performance improvement point
- Any good design pattern on here
function loadMovies() {
const url = 'http://moviedatas.com/movies';
const movieList = $('.movie_list');
setOnLoading(movieList);
$.ajax({
method: 'GET',
url: url,
data: {
count: 10
},
success: function(response) {
movieList.each(function() {
const wrapper = $(this);
render(wrapper, items);
});
},
error: function(error) {
onError(movieList);
}
})
}
function setOnLoading(movieList) {
movieList.each(function() {
$(this).html('Loading...');
});
}
function render(wrapper, items) {
const template = `<div class="movie_item">
<div class="title">{title}</div>
<div class="desc">{description}</div>
</div>`;
let movies = '';
for (let i = 0; i < items.length; i++) {
movies += template
.replace('{title}', items[i].title)
.replace('{description}', items[i].description);
}
wrapper.html(movies);
}
function onError(movieList) {
movieList.each(function() {
$(this).html('');
});
}
jquery ajax
jquery ajax
New contributor
New contributor
New contributor
asked 9 mins ago
ScottScott
1
1
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Scott is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217246%2ffetching-movie-data-using-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Scott is a new contributor. Be nice, and check out our Code of Conduct.
Scott is a new contributor. Be nice, and check out our Code of Conduct.
Scott is a new contributor. Be nice, and check out our Code of Conduct.
Scott is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217246%2ffetching-movie-data-using-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown