Return JSON Response in CodeIgniter controller

Today, We want to share with you Return JSON Response in CodeIgniter controller.In this post we will show you send json response codeigniter example, hear for codeigniter json encode array we will give you demo and example for implement.In this post, we will learn about codeigniter json response with an example.

Return JSON Response in CodeIgniter controller

There are the Following The simple About Return JSON Response in CodeIgniter controller Full Information With Example and source code.

As I will cover this Post with live Working example to develop get json response php codeigniter, so the codeigniter return json header for this example is following below.

Also Read :  Laravel Merge Multiple collections Object And Array

Json Response

public function returnMyProductJson() { 
  header('Content-Type: application/json');
  $productArray = ['id'=>9898, 'name'=>'Mobile'];
  echo json_encode($success);
} 

Completed Source Code

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

 public function index(){

  // load base_url
  $this->load->helper('url');

  // load view
  $this->load->view('product_view');
 }

 public function productDetails(){
  // POST data
  $postProductData = $this->input->post();

  //load model
  $this->load->model('Main_model');

  // get data
  $data = $this->Main_model->getProductDetails($postProductData);

  echo json_encode($data);
 }

}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to send json response from controller in codeigniter ?.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.