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 ?
- Angular Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?
- Angular 9 Image Upload with Crop Example
- Files Upload on Button Click in PHP Dropzone Example
- PHP Dropzone Allow only One File to Upload Example
- PHP Dropzone Allow only Images to Upload Example
- PHP Dropzone Delete Uploaded File Example
- Livewire CRUD Laravel 7 Example