0

enter image description here

I am trying to do create text-box auto-complete with jquery. But something goes wrong when I check it in debuger it shows the every value but it not showing in text-box drop-down on view page. I'm newbie all help would be appreciated.

here's my view code.

<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

<script type="text/javascript">
    $(function(){
        $("#location").autocomplete({
            source: 'set_location'
        });     
    });
</script>
<form action= "#">
    <table>
        <tr>
            <td><label for='location'>Location</label></td>
            <td><input id="location" type="text" size="50" placeholder="Enter a location" name= "location"> </td>
        </tr>           
    </table>
</form>

here's my controller code

if(isset($_GET['term'])){
    $location = strtolower($_GET['term']);      
    $query = $this->venues_model->set_location($location);          
    echo $query;
}

here's my model code

$this->db->select('*');
$this->db->like('location', $location);
$query = $this->db->get('venue_details');

if(count($query->result_array()) > 0){ 
    foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['location']));
    }
    echo json_encode($row_set);
}
2
  • Any error in console?? Commented Oct 27, 2015 at 7:13
  • No it not showing anything. Commented Oct 27, 2015 at 7:14

3 Answers 3

1

try this,

if(isset($_GET['term'])){
$location = strtolower($_GET['term']);      
echo $this->venues_model->set_location($location);          
}

in model

function set_location() {
    $row_set = array();
    $this->db->select('*');
    $this->db->like('location', $location);
    $query = $this->db->get('venue_details');

    if (count($query->result_array()) > 0) {
        foreach ($query->result_array() as $row) {
            $row_set[] = htmlentities(stripslashes($row['location']));
        }

    }

    return json_encode($row_set);
}

also this,

source: '<?= base_url("controller/set_location") ?>'
Sign up to request clarification or add additional context in comments.

13 Comments

Check i have changed my model
in console is it printing anything??
yes after every key press it update and showing the values.
can u add that screenshot??
in this, only echo of json should be present. no var_dump, no any other echo and no loading view
|
0

You have to return from your model file and echo from your controller

Model

$this->db->select('*');
$this->db->like('location', $location);
$query = $this->db->get('venue_details');

if(count($query->result_array()) > 0){ 
    foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['location']));
    }
    return json_encode($row_set);// return from model
}

Controller

if(isset($_GET['term'])){
    $location = strtolower($_GET['term']);      
   echo  $query = $this->venues_model->set_location($location);          
}

And change your path to

source: '<?php echo base_url();?>index.php/controller/function'

8 Comments

You need to call a ajax link to get your data from your controller
i'm following this link
YOu need to check your path i tinl it would be source: '<?php echo base_url()./index.php/controller/function'
what is index.php here
Check without index.php <?php echo base_url();?>controller/function
|
0

just add ui-widget to your div. Make sure to reference jquery ui

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.