Ajax does not receive data in json [closed]

1

Personal I've created a function with Ajax that should return the posts that are in the database. Ajax requests a PHP script that it responds with a JSON but I get the following message in the browser console

  

Synchronous XMLHttpRequest should not be used on the main thread due to   to its detrimental effects to the user experience. For more   information link

Follow the front-end code:

$(document).ready(function () {
    var count = 0;
    var value = 4;
    function getOtherPubli() {
        var stringUrl = $(location).attr('href').split("/");
        var type = stringUrl[2];
        var id = stringUrl[3];
        $.ajax({
            method: "POST",
            url: "/sys/etc/other-publi.php",
            data: {noPost: id, q: value, b: count, type: type}

        }).done(function (answer) {
            if (answer.status == 'ok') {
                $('contant-others-publi').html(answer.string);
                count += value;
            } else {
                console.log("System (other post) error. Code: " + answer.status);
            }


        }).fail(function (jqXHR, textStatus) {
            console.log("System (other post) error. Request failed: " + textStatus);

        });
    }
    getOtherPubli();
});

PHP code:

<?php

include_once 'sys/lib.php';
include_once 'sys/db/base0.php';

$id = [];
$tl = [];
$cp = [];
$string = '';
$res = ['status'=>null,'string'=>null];

if (isAjax()) {
    $getPost = ["nopost" => (int) $_POST['noPost'], "q" => (int) $_POST['q'], "b" => (int) $_POST['b'], "type" => clrSqli($_GET['type'])];
    $db = connectdb();
    $get = $db->prepare("SELECT id,title,coverofpost FROM 'posts' WHERE id <> :notPost AND type = :type ORDER BY 'date' DESC LIMIT :begin, :end");
    $get->bindValue(":notPost", $getPost['nopost'], PDO::PARAM_INT);
    $get->bindValue(":begin", $getPost['q'], PDO::PARAM_INT);
    $get->bindValue(":end", $getPost['b'], PDO::PARAM_INT);
    $get->bindValue(":type", $getPost['type'], PDO::PARAM_STR);
    $get->execute();
    if ($get->rowCount() > 0) {
        while ($data = $get->fethc(PDO::FETCH_ASSOC)) {
            array_push($id, $data['id']);
            array_push($tl, $data['title']);
            array_push($cp, $data['coverofpost']);
        }
        $length = count($id);
        for ($i = 0;$i < $length;$i ++) {
            $string .= '<div class="other-publi" data-id="'.$id[$i].'">
                        <div class="limit-img-other-publi">
                            <img class="img-other-post" src="'.$cp[$i].'" alt="FOTO"/>
                        </div>
                        <div class="title-other-publi">
                            <span>'.$tl[$i].'</span>
                        </div>
                     </div>';
        }
        $res['status'] = 'ok';
        $res['string'] = $string;
    } else {
        $res['status'] = 404;
    }
} else {
    $res['status'] = 403;
}
echo json_encode($res,true);
    
asked by anonymous 28.12.2016 / 22:33

0 answers