Welcome Guest, Not a member yet? Register   Sign In
JavaScript Fetch returns an error when in development mode.
#1

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:
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

CI_ENVIRONMENT development 

Controller: TesApi.php
PHP Code:
public function tesApi()
    {
        $data = ['id' => 1];
        return json_encode($data);
    

View: tesapi.php
PHP Code:
<body>
    Api test using fetch when in development mode
    
<script>
    fetch('tesapi')
        .then(response => response.json())
        .then(json => console.log(json));
    </script>
</
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}());
void 0===window.kintRich&&(window.kintRich=function(){"use strict";var l....
Reply


Messages In This Thread
JavaScript Fetch returns an error when in development mode. - by Renta Ardhana - 07-12-2024, 08:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB