Model 

```
<?php if (! defined('BASEPATH')) exit('No direct script access');

class Ajax_model extends CI_Model
{
    public function __construct()
        {
                $this->load->database();
        }

    public function search($data) {
        $this->db->select('title');
        $this->db->select('text');
        $this->db->like('title', $data);
        $query = $this->db->get('news', 10);

        return $query->result_array();
    }

}

?>

```

Controller

```
<?php
// application/controller/ajax.php

class Ajax extends CI_Controller 
{
        public function __construct()
        {
                parent::__construct();
                $this->load->model('ajax_model');
        }

        public function getdata($param = '')
           {
            // Get data from db 
            $data['ajaxdata'] = $this->ajax_model->search($param);
            $data['ajaxdata'] = json_encode($data['ajaxdata']);
            $this->load->view('ajax/index', $data);

            //echo $data['ajaxdata'];
           }

}

?>

```

View

```
<!-- application/views/ajax/index.php-->

<p><?=$ajaxdata?></p>

```

Finally, in my header where my form is; I have my JavaScript

```
<div id="searchresults"></div>

                <script>

   // This is the jQuery Ajax call
   function doSearch()
   {
      $.ajax({
         type: "GET",
         url:"localhost/codeigniter/index.php/ajax/getdata/" + $("#mysearch").val(),
         success:function(data){

         $("#searchresults").html(data);
      }});
   }

</script>

```

Maybe I could do this differently?

My result at the moment shows like this 

```
[{"title":"Cousy","text":"A very comfortable luxury double bed room"},{"title":"Romance","text":"This is a lovely room for couple on honey moon double bed"}]

```

Its showing records correctly but in same line. I want it to appear seperately and in href format