Currently I'm trying to load in the content of a select with an AJAX call. To do this I have an AJAX that sends a request to my controller and returns the response.Now this does return the response, but it also shows an error saying JSON.parse: unexpected character at line 1 column 2 of the JSON data. Here is what it shows in console:
Now the following is the code I'm using to achieve this:
View Class:
<label for="code" class="control-labels text-nowrap mr-3">Search Contacts</label>
<input id="owners"  name="owners_det" list="owners_list" placeholder="Start typing to show contacts" value="<?php echo $owner_details; ?>" type="text">
<input type="hidden" name="owners_id" id="owners_id" value="<?php echo $owner_id; ?>" />
<datalist id="owners_list">
</datalist>
AJAX:
function getcontacts(obj){
  var dataString = new Object();
  $.ajax({
        type: "GET",
        dataType:"json",
        url: "<?php echo site_url('listings/getContacts'); ?>/"+obj,
        success: function(response){
            console.log(response);
            var responseText = JSON.parse(response);
            $('#owners_list').html(responseText,data);
        }
    });  
}
Controller Class:
public function getContacts($id){
    $option = "<option value='0'>Select</option>";
    $modelList = $this->listings_model->get_contact('firstname,lastname,mobile,email,agents_id,title,id,refno');  
    foreach($modelList as $m){
        $option .= "<option value='".$m['firstname']." ".$m['lastname']." - ".$m['refno']."' id='".$m['id']."'>".$m['firstname']." ".$m['lastname']." - ".$m['refno']."</option>";
    }
    $data = array(
        'data' => $option
    );
    echo json_encode($data);
}
It seems that a data entry has a unusable character and the data is too big for me to try and find that character. So I was thinking if it would be possible to convert this into a JSON format instead?
