javascript — localhost работает нормально, размещенные ошибки с & quot; Uncaught TypeError: Невозможно прочитать свойство ‘record’ из null & quot;

Я столкнулся с ошибкой:

**Uncaught TypeError: Cannot read property 'record' of null.**

Я хочу отображать данные с помощью ajax в таблице, но есть проблема. Когда я открываю страницу из localhost, она работает нормально, но когда я открываю ее с размещенного там сайта является проблема.

 if(data.record != null ) {
$.each(data.record, function(index, element){
var post_status = '';
if(element.post_status == 'pending'){
post_status = '(pending)';
}

$('table#tbl-artikel').find('tbody').append(
'<tr>'+
'  <td width="2%"><input type="checkbox" name="post_id[]" value="'+element.post_ID+'"></td>'+
'  <td width="50%"><a class="link-edit" href="artikel#edit?id='+element.post_ID+'">'+element.post_title+'</a> <strong>'+post_status+'</strong></td>'+
'  <td width="10%"><i class="icon-comment-alt"></i> <span class="value">'+element.comment_count+'</span></td>'+
'  <td width="10%"><i class="icon-eye-open"></i> <span class="value">'+element.post_counter+'</span></td>'+
'  <td width="12%"><i class="icon-time"></i> <span class="value">'+moment(element.post_date).fromNow()+'</span></td>'+
'  <td width="16%" class="td-actions">'+
'    <a href="artikel#edit?id='+element.post_ID+'" class="link-edit btn btn-small btn-info"><i class="btn-icon-only icon-pencil"></i> Edit</a>'+
'    <a href="artikel#hapus?id='+element.post_ID+'" class="btn btn-invert btn-small btn-info"><i class="btn-icon-only icon-remove" id="hapus_1"></i> Hapus</a>'+
'  </td>'+
'</tr>'
)
});
}else{
console.log(data);
}

-1

Решение

измените свой код на:

 if(data != null && data.record != null ) {
$.each(data.record, function(index, element){
var post_status = '';
if(element.post_status == 'pending'){
post_status = '(pending)';
}

$('table#tbl-artikel').find('tbody').append(
'<tr>'+
'  <td width="2%"><input type="checkbox" name="post_id[]" value="'+element.post_ID+'"></td>'+
'  <td width="50%"><a class="link-edit" href="artikel#edit?id='+element.post_ID+'">'+element.post_title+'</a> <strong>'+post_status+'</strong></td>'+
'  <td width="10%"><i class="icon-comment-alt"></i> <span class="value">'+element.comment_count+'</span></td>'+
'  <td width="10%"><i class="icon-eye-open"></i> <span class="value">'+element.post_counter+'</span></td>'+
'  <td width="12%"><i class="icon-time"></i> <span class="value">'+moment(element.post_date).fromNow()+'</span></td>'+
'  <td width="16%" class="td-actions">'+
'    <a href="artikel#edit?id='+element.post_ID+'" class="link-edit btn btn-small btn-info"><i class="btn-icon-only icon-pencil"></i> Edit</a>'+
'    <a href="artikel#hapus?id='+element.post_ID+'" class="btn btn-invert btn-small btn-info"><i class="btn-icon-only icon-remove" id="hapus_1"></i> Hapus</a>'+
'  </td>'+
'</tr>'
)
});
}else{
console.log(data);
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector