Failed to return JSON "SyntaxError: Unexpected token in JSON at position 0"

0

mysqli_connect.php

<?php
//db details
$db_host = '127.0.0.1';
$db_user = 'root';
$db_pass = '';
$db_name = 'db_ws_restphp';

//connect and select db
$con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

?>

index.php

<?php
require_once('include/mysqli_connect.php');
header('content-type:application/json; charset=utf-8');

$actionName = $_POST["actionName"];

//Select
if($actionName == "selectPost"){
    $seachKey = isset($_POST["seachKey"]) ? $_POST["seachKey"] : '';

    if(!empty($seachKey))
        $query = "SELECT * FROM tb_post where post_title like '%$seachKey%' ORDER BY post_id DESC";
    else
        $query = "SELECT * FROM tb_post ORDER BY post_id DESC";
    $result = mysqli_query($con, $query);

    $rowCount = mysqli_num_rows($result);

    if($rowCount > 0){
        $postData = array();
        while($row = mysqli_fetch_assoc($result)){
            $postData[] = $row;
        }
        $resultData = array('post_status' => true, 'postData' => $postData);
    }else{
        $resultData = array('post_status' => false, 'message' => 'No se encontro Post(s) ...');
    }

    echo json_encode($resultData);
} ?>
    
asked by Juam Glez 05.09.2018 в 00:53
source

0 answers