Dear fellow codeigniter development
I am a new user of ci4. And I'm sorry if my question sounds stupid. I am trying to make a query select statement. And I found that there is an error Failed to parse json string, error: "Type is not supported". I don't know what this error is. And I also don't know how to debug this error.
This is the error and my controller plus with my vue.js function which is call the controller
Code:
<br />
<b>Fatal error</b>: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in C:\ci4_project\paygate\vendor\codeigniter4\framework\system\Format\JSONFormatter.php:41
Stack trace:
#0 C:\ci4_project\paygate\vendor\codeigniter4\framework\system\Format\JSONFormatter.php(41): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 C:\ci4_project\paygate\vendor\codeigniter4\framework\system\API\ResponseTrait.php(348): CodeIgniter\Format\JSONFormatter->format(Array)
#2 C:\ci4_project\paygate\vendor\codeigniter4\framework\system\API\ResponseTrait.php(99): CodeIgniter\Debug\Exceptions->format(Array)
#3 C:\ci4_project\paygate\vendor\codeigniter4\framework\system\Debug\Exceptions.php(132): CodeIgniter\Debug\Exceptions->respond(Array, 500)
#4 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(CodeIgniter\Format\Exceptions\FormatException))
#5 {main}
thrown in <b>C:\ci4_project\paygate\vendor\codeigniter4\framework\system\Format\JSONFormatter.php</b> on line <b>41</b><br />
{
"title": "ErrorException",
"type": "ErrorException",
"code": 500,
"message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse json string, error: \"Type is not supported\". in C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php:41\nStack trace:\n#0 C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php(41): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Type is not sup...')\n#1 C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(348): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(99): CodeIgniter\\Debug\\Exceptions->format(Array)\n#3 C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\Debug\\Exceptions.php(132): CodeIgniter\\Debug\\Exceptions->respond(Array, 500)\n#4 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(CodeIgniter\\Format\\Exceptions\\FormatException))\n#5 {main}\n thrown",
"file": "C:\\ci4_project\\paygate\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php",
"line": 41,
"trace": [
{
"function": "shutdownHandler",
"class": "CodeIgniter\\Debug\\Exceptions",
"type": "->",
"args": []
}
]
}
This is my controller
PHP Code:
public function search(){
$this->db = \Config\Database::connect();
$user_id = $this->request->getPOST('search');
if($user_id){
$sql = "SELECT pay_daftarid.di_id, pay_daftarid.di_nama, pay_daftarid.di_nokp, pay_daftarid.di_telefon, pay_daftarid.di_emel,
pay_daftarid.di_alamat1, pay_daftarid.di_poskod,pay_daftarid.di_kod_bandar, pay_daftarid.di_kod_negeri,
pay_daftarid.di_kod_negara,
hrp_ruj_negara.keterangan as negara,
hrp_ruj_negeri.keterangan as negeri,
hrp_ruj_bandar.nama_bandar
FROM pay_daftarid
JOIN hrp_ruj_negara ON hrp_ruj_negara.kod = di_kod_negara
JOIN hrp_ruj_negeri ON hrp_ruj_negeri.kod = di_kod_negeri
JOIN hrp_ruj_bandar ON kod_bandar = di_kod_bandar
WHERE pay_daftarid.di_nokp = '$user_id'";
$data = $this->db->query($sql);
return $this->respond($data);
}
}
my vue.js function which is call the controller
Code:
get_id(){
var self = this;
$.post(base_url + '/api/seminar/search', {
search: self.search, //self.search ( data yang nk disearch)
}, function(res){ //res adalah daripada API
self.selected = res.data[0];
console.log(self.contents[0].di_nama);
// console.log(res);//nk tgk apa yg server respond
});
},
I really need help with this issue because I don't know how to fix it. I really appreciate for your time and energy. Thank you.