Я успешно извлек данные с помощью этого кода, но проблема, с которой я сталкиваюсь, заключается в том, что данные появляются в нескольких местах, например, "Том", появляется Том, Том, Том ...
<div class="row">
<div class="col-12">
<div class="c-table-responsive@wide" id="responsecontainer">
<!-- User Json Tabualated Data Display -->
</div>
</div>
</div>
А вот мой код JSON:
{
"userID": "1",
"name": "Precious Tom",
"email": "tomprezine@example.com",
"password": "64a9f0ea7bb98050296b649e85484145",
"gender": null,
"birthday": null,
"location": null,
"avatar": null,
"phone": "8175555649",
"userToken": "n89jf8h3i3n8wywc",
"is_verified": "0",
"dateJoined": "Wed, 02 May 2018 16:20:35 +0100"
}
А вот мой код Ajax:
$(document).ready(function(){
$(document).ready(function(){
$.ajax({
type: 'GET',
url: '../Module/listcustomers',
data: {},
dataType: 'json',
success: function (data) {
var tableContent = '<table class="c-table">';
tableContent += '<thead class="c-table__head">\
<tr class="c-table__row">\
<th class="c-table__cell c-table__cell--head">Customer</th>\
<th class="c-table__cell c-table__cell--head">Email</th>\
<th class="c-table__cell c-table__cell--head">Gender</th>\
<th class="c-table__cell c-table__cell--head">Phone</th>\
<th class="c-table__cell c-table__cell--head">Date Joined</th>\
<th class="c-table__cell c-table__cell--head">Is Verified</th>\
</tr>\
</thead>';
if(data) {
tableContent += '<tbody>';
$.each(data, function( key, value ) {
tableContent += '<tr class="c-table__row">';
tableContent += '<td class="c-table__cell"><a href=<?php echo BASEPATH . "Dash/user-profile/"?>'+data.userID+'>'+data.name+'</a></td>';
tableContent += '<td class="c-table__cell">'+data.email+'</td>';
tableContent += '<td class="c-table__cell">'+data.gender+'</td>';
tableContent += '<td class="c-table__cell">'+data.phone+'</td>';
tableContent += '<td class="c-table__cell">'+data.dateJoined+'</td>';
tableContent += '<td class="c-table__cell">'+farmshopp.verificationButton(data.is_verified)+'</td>';
});
}
tableContent += "</tbody>";
tableContent += "</table>";
$("#responsecontainer").html(tableContent);
}
});
});
});
Дублированный результат:
Аякс Джсон:
Понятия не имею, что делать дальше, поэтому, пожалуйста, рассчитываю на вашу помощь