In this article, we will learn how to send json response from controller method in codeigniter application. When we work with jquery ajax at that time we need to manage using json. If you got error then it will return json array with error. So You can simple send json response from controller function in codeigniter application by following example:
Let's see example as bellow:
Json Response
public function returnMyJson() {
header('Content-Type: application/json');
$myArray = ['id'=>12, 'name'=>'Topi'];
echo json_encode($success);
}
Thanks for visit...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example