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.

Json Response

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

Completed Source Code


  // load view

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

  //load model

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

  echo json_encode($data);


Angular 6 CRUD Operations Application Tutorials

Read :


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 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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Get User IP Address
  2.   Angular 9/8 Material Checkbox Examples
  3.   Remove Last Character from String in JavaScript
  4.   Laravel Calculate Age from Date of Birth in MySQL
  5.   Login Signup with Laravel
  6.   WooCommerce Get Product General Info
  7.   Laravel Check Array Empty in Blade Example
  8.   Free Unlimited Cloud Storage Types providers Advantages Examples
  9.   Multiple Ternary Operator in php Examples
  10.   how to check empty array in laravel controller?