0

I am using meekro db to fetch data from database and when I return object as json format then ajax call goes to error

  $(".cat").click(function() {
    var value = $(this).attr('id');

    $.ajax({

        url:"/psl/ajax/get_words.php",
        method:"post",
        dataType: "json",
        data:{ id: value },


        success:function(response)    // success part does not execute
        {
            var data = JSON.parse(response);
            alert( data );
        },

        error:function (msg) {       // error part executes every time
           alert('error');
        }
    });

});

And the code which is being used to fetch data from database get_words.php

    <?php
    require_once '../inc/initDb.php';
    $id = $_POST['id'];
    $words = DB::query("select * from words where category_id = '$id'");
    if (DB::count() > 0)
    {
        echo json_encode($words);
    }
lalithkumar
  • 3,480
  • 4
  • 24
  • 40

0 Answers0