![]() |
JavaScript Fetch returns an error when in development mode. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: JavaScript Fetch returns an error when in development mode. (/showthread.php?tid=91276) |
JavaScript Fetch returns an error when in development mode. - Renta Ardhana - 07-12-2024 I want to test my API call using CI4. In development mode, I encountered errors in the browser console. How can I fix this? .env PHP Code: #-------------------------------------------------------------------- Controller: TesApi.php PHP Code: public function tesApi() View: tesapi.php PHP Code: <body> Error in browser console: Code: Uncaught (in promise) SyntaxError: Unexpected token '<', "<script cl"... is not valid JSON Code: <script class="kint-rich-script">void 0===window.kintShared&&(window.kintShared=function(){"use strict";var e={dedupe:function(e,n){return[].forEach.call(document.querySelectorAll(e),function(e){e!==(n=n&&n.ownerDocument.contains(n)?n:e)&&e.parentNode.removeChild(e)}),n},runOnce:function(e){"complete"===document.readyState?e():window.addEventListener("load",e)}};return window.addEventListener("click",function(e){var n;e.target.classList.contains("kint-ide-link")&&((n=new XMLHttpRequest).open("GET",e.target.href),n.send(null),e.preventDefault())}),e}()); RE: JavaScript Fetch returns an error when in development mode. - ozornick - 07-12-2024 Disable toolbar for API URLs ![]() https://codeigniter4.github.io/userguide/incoming/filters.html#except-for-a-few-uris RE: JavaScript Fetch returns an error when in development mode. - Renta Ardhana - 07-12-2024 (07-12-2024, 10:53 AM)ozornick Wrote: Disable toolbar for API URLsyes it works. I moved toolbar filter from required to globals. Then add exception on it. Code: public array $required = [ then.. Code: public array $globals = [ RE: JavaScript Fetch returns an error when in development mode. - kenjis - 07-15-2024 (07-12-2024, 10:53 AM)ozornick Wrote: Disable toolbar for API URLs This works, but not good. Because if you send correct responses, you don't need to disable the toolbar filter. RE: JavaScript Fetch returns an error when in development mode. - kenjis - 07-15-2024 PHP Code: public function index() Code: $ curl localhost:8080 -v PHP Code: public function index() Code: $ curl localhost:8080 -v The following code is better. PHP Code: public function index() https://codeigniter.com/user_guide/outgoing/response.html#setting-the-output RE: JavaScript Fetch returns an error when in development mode. - Renta Ardhana - 07-16-2024 (07-15-2024, 03:36 PM)kenjis Wrote: The following code is better. thanks @kenjis, I need to get used to this (the better) PHP Code: $this->response->setJSON ($var) or this one: PHP Code: public function index() |