I'm trying to create a function that, given the type of post, returns the findings that are in the database using jQuery-min-3.1.1.js
, PHP, and JSON to exchange information. However I get the following error message: TypeError: b is undefined jquery.min.js:3:6371
I did not declare this var in my script, and I do not understand why the error occurred.
jquery / javascript:
function loadPost() {
var size = arrayPost.length;
var imgPath = '/images/upload/poster/';
var post = arrayPost;
for (i = 0; i < post.rows; i++) {
$('.side-left').append(htmlPost);
$($('.cont-desc')[i]).attr('title', post.description[i]);
$($('.cont-type')[i]).html(post.type[i]);
$($('.cont-url')[i]).attr('href', post.url[i]);
$($('.cont-url-img')[i]).attr('src', imgPath + post.poster[i]);
$($('.cont-demo')[i]).html(post.title[i]);
}
}
//navbar---------------------------------
var bcd = 0;
var ecd = 12;
function mountNewPubli(d) {
$('.side-left').html('');
arrayPost = d;
loadPost();
$('.side-left').append('<button class="btnloadmore" type="button">Carregar +</button>');
}
$('.search-label').click(function (ev) {
ev.preventDefault();
var label = $(this).attr('data-type');
$.ajax({
type: 'GET',
url: '/sys/etc/search-label.php',
data: {type: label, b: bcd, e: ecd}
}).done(function (d) {
console.debug(d)
if (d.status == 404) {
callError(404, 'Não foi possível obter ' + $(this).html() + '{search-label: return 404}');
} else if (d.status == 200) {
bcd = (ecd + 1);
ecd += 12;
mountNewPubli();
} else {
console.debug(d);
}
}).fail(function () {
callError(404, 'Não foi possível obter ' + $(this).html() + ' {Path_not_found}');
});
});
PHP:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/lib.php';
if (isAjax()) {
if (isset($_GET['type'])) {
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/class/class-posts.php';
$post = new Publication();
$return = $post->searchLabel($_GET['type'], (int) $_GET['b'], (int) $_GET['e']);
}
header('Content-Type: application/json');
echo json_encode($return);
}