0

I am building my first real project and using D3.js library for visualization. I was trying to deploy a Bar Chart in D3.js but I am having some problem in my JSON response in d3.json() function. Here is my code:

d3.json("<?=  base_url(). "/testingGraph";?>").then( function(data) {
    console.log(data);
})

The response looks good, with status of 200. Here is a look into it:
Response: enter image description here Preview: enter image description here But the console Tab is giving following errors:

VM1686:2 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 456
Promise.then (async)        
(anonymous)

Here is my Controller sending the data:

    public function testingGraph()
    {
        $db = \Config\Database::connect();

        $dataTableQuery = $db->query("SELECT agent_name, COUNT(id) as transfer FROM `transfers` GROUP BY agent_name ORDER BY transfer DESC LIMIT 10");
        $result = $dataTableQuery->getResultArray();
        echo json_encode($result, JSON_NUMERIC_CHECK);
    }

By the looks of it, I feel I have done everything right, but I can not seem to find the solution to the issue. My response is JSON from PHP, and the preview and status looks good to me, what am I doing wrong?

Aun Zaidi
  • 103
  • 1
  • 9
  • Your screenshot shows a bunch of ` – JLRishe Jun 27 '21 at 10:54
  • @JLRishe it is? Why is it even there? Although I am using Codeigniter 4, but on this specific page, I am not using any other page as inheritance. Do you know what could be the issue if this is the issue? – Aun Zaidi Jun 27 '21 at 10:58
  • No idea. I haven't used Codeigniter. It looks like some kind of "debugbar" is being inserted into the response. Do you have any idea where that would be coming from? – JLRishe Jun 27 '21 at 11:38
  • @JLRishe absolutely not, I have used so many API calls before and there has never been a response like that. Never in my other requests before, I have come across this. But now I'll shift the focus of my R&D – Aun Zaidi Jun 27 '21 at 11:44
  • Looks relevant: https://forum.codeigniter.com/thread-75778.html Seems to be a Codeigniter feature. – JLRishe Jun 27 '21 at 11:46
  • @JLRishe thanks. I actually just came across [link](https://forum.codeigniter.com/thread-74553.html) this and was able to solve. You were right, the Codeingiter's debugger was breaking my json response. – Aun Zaidi Jun 27 '21 at 11:53

0 Answers0