Load table via list ajax
I'm trying to load a table via post ajax, but it's not loading properly.
table
:
<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>
And here is how I am loading:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.
javascript jquery ajax
|
show 1 more comment
I'm trying to load a table via post ajax, but it's not loading properly.
table
:
<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>
And here is how I am loading:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.
javascript jquery ajax
1
$("#tableestoque").append("<tr"
=>$("#tableestoque tbody").append("<tr>"
. You are missing thetbody
element and the closing of the<tr>
.
– Dekel
Nov 19 '18 at 13:20
just a typo - you missed the>
from your<tr
, should be<tr>
– ADyson
Nov 19 '18 at 13:20
1
I think you need append you html to<tbody>
, not to<table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25
|
show 1 more comment
I'm trying to load a table via post ajax, but it's not loading properly.
table
:
<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>
And here is how I am loading:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.
javascript jquery ajax
I'm trying to load a table via post ajax, but it's not loading properly.
table
:
<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>
And here is how I am loading:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.
javascript jquery ajax
javascript jquery ajax
asked Nov 19 '18 at 13:18
marianac_costamarianac_costa
1358
1358
1
$("#tableestoque").append("<tr"
=>$("#tableestoque tbody").append("<tr>"
. You are missing thetbody
element and the closing of the<tr>
.
– Dekel
Nov 19 '18 at 13:20
just a typo - you missed the>
from your<tr
, should be<tr>
– ADyson
Nov 19 '18 at 13:20
1
I think you need append you html to<tbody>
, not to<table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25
|
show 1 more comment
1
$("#tableestoque").append("<tr"
=>$("#tableestoque tbody").append("<tr>"
. You are missing thetbody
element and the closing of the<tr>
.
– Dekel
Nov 19 '18 at 13:20
just a typo - you missed the>
from your<tr
, should be<tr>
– ADyson
Nov 19 '18 at 13:20
1
I think you need append you html to<tbody>
, not to<table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25
1
1
$("#tableestoque").append("<tr"
=> $("#tableestoque tbody").append("<tr>"
. You are missing the tbody
element and the closing of the <tr>
.– Dekel
Nov 19 '18 at 13:20
$("#tableestoque").append("<tr"
=> $("#tableestoque tbody").append("<tr>"
. You are missing the tbody
element and the closing of the <tr>
.– Dekel
Nov 19 '18 at 13:20
just a typo - you missed the
>
from your <tr
, should be <tr>
– ADyson
Nov 19 '18 at 13:20
just a typo - you missed the
>
from your <tr
, should be <tr>
– ADyson
Nov 19 '18 at 13:20
1
1
I think you need append you html to
<tbody>
, not to <table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
I think you need append you html to
<tbody>
, not to <table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25
|
show 1 more comment
2 Answers
2
active
oldest
votes
I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.
var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;
data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});
add a comment |
It looks like you need to append your html to <tbody>
like this:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque tbody").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
add a comment |
Your Answer
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: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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%2fstackoverflow.com%2fquestions%2f53375500%2fload-table-via-list-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.
var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;
data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});
add a comment |
I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.
var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;
data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});
add a comment |
I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.
var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;
data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});
I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.
var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;
data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});
answered Nov 19 '18 at 13:28
dganencodganenco
2217
2217
add a comment |
add a comment |
It looks like you need to append your html to <tbody>
like this:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque tbody").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
add a comment |
It looks like you need to append your html to <tbody>
like this:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque tbody").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
add a comment |
It looks like you need to append your html to <tbody>
like this:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque tbody").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
It looks like you need to append your html to <tbody>
like this:
$.each(data.listaEstoque, function (i, item) {
$("#tableestoque tbody").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});
answered Nov 19 '18 at 13:22
Oleg NurutdinovOleg Nurutdinov
358213
358213
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
add a comment |
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
Did you even read the comments before answering ?
– Dekel
Nov 19 '18 at 13:23
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
@Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)
– Oleg Nurutdinov
Nov 19 '18 at 13:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f53375500%2fload-table-via-list-ajax%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
1
$("#tableestoque").append("<tr"
=>$("#tableestoque tbody").append("<tr>"
. You are missing thetbody
element and the closing of the<tr>
.– Dekel
Nov 19 '18 at 13:20
just a typo - you missed the
>
from your<tr
, should be<tr>
– ADyson
Nov 19 '18 at 13:20
1
I think you need append you html to
<tbody>
, not to<table>
– Oleg Nurutdinov
Nov 19 '18 at 13:20
Not sure what you mean by "clean only the tr".
– Dekel
Nov 19 '18 at 13:23
@Deker I need to clear the included data, not the header
– marianac_costa
Nov 19 '18 at 13:25