Retrieve and display json data from codeigniter function

Retrieve and display json data from codeigniter function

How can to display data from database (SQL) using ajax (json) and codeigniter or php? i've tried to do it but the result is "undefined" here is my code:

How can to display data from database (SQL) using ajax (json) and codeigniter or php? i've tried to do it but the result is "undefined" here is my code:

jquery codes:

$('[id^="menuitem_"]').on('click',function(){
var menuID = $(this).attr('id').split("_")[1];
        $.ajax({
            url:"<?php echo base_url();?>Vendors_search/Get_Business_By_Type",
            method:"POST",
            dataType: "text",
            data: {menuID:menuID},
            success:function(resp){

              var obj = $.parseJSON(resp);
              var values = Object.values(obj); 
              $.each(obj,function(key,val){

              $('.business_id').append('<strong>' + val.business_name + '</strong>');
            });
    }

        });

Codeigniter codes:

function Get_Business_By_Type(){
    $obj = $this->input->post('menuID');     
    if($this->Search_obj_model->getBusinessType($obj)){
    $bus_type = $this->Search_obj_model->getBusinessType($obj);  
    $result['business_details'] = $this->Search_obj_model->getBusinessType($obj);
        }
        else{
            $result['message'] = 'Oooops! We could not find your request. Try again later';
        }
    $this->output->set_content_type('application/json');
    $this->output->set_output(json_encode($result));
    $string = $this->output->get_output();
    echo $string;
    exit();
 }

php json ajax codeigniter

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire CodeIgniter Developer

Want to create unique, scalable web and app solutions? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, Expert CodeIgniter developer works particularly for you and your project. You can **[Hire CodeIgniter...

How to Send AJAX request with CSRF token in CodeIgniter

How to Send AJAX request with CSRF token in CodeIgniter - In this tutorial, I show how you can enable CSRF protection and regenerate hash for next AJAX request and pass hash in AJAX request in the CodeIgniter.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

how to build a new json string from existing json string

I have multiple files that contain json data that looks like this:

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...