Welcome Guest, Not a member yet? Register   Sign In
autocomplete not working in ci3?
#1

Hi Coders,


i try many times in ci3 to work search autocomplete but im not luck. but when i try on ci2. it working good. 

i dont know if there is, that i need to set or to change. any help please . . . 
Reply
#2

i dont know if json is working well on CI3?
Reply
#3

(This post was last modified: 02-23-2015, 05:26 AM by Nichiren.)

Without more information, CI JSON support is probably not the problem. Assuming you're using AJAX POSTs, I can guess that either your CSRF protection is enabled and csrf_regenerate is set to TRUE or your sessions are now somehow interfering with your autocomplete code. If it's the former, you can either exclude your AJAX URIs in your csrf_exclude_uris setting or set csrf_regenerate to FALSE (if your application doesn't require tight CSRF protection).
Reply
#4

Thanks for you reply. . . here are my autocomplete code.

VIEW 


Code:
<script type="text/javascript">
                $(function(){
          $("#birds").autocomplete({
            source: "<?php echo base_url();?>home/search_description" // path to the get_birds method
          });
            });
</script>
Code:
<input type="text" class="form-control" id="birds" value = "" name = "desc" placeholder="Required *">

CONTROLLER
Code:
public function search_description()
    {
    if (!isset($_GET['term']))
      {
          exit;
      }
          $this->load->model('model_service');    
          $qs = strtolower($this->input->get('term'));     
          $this->model_service->get_stocks($qs);
    }

MODEL
Code:
public function get_stocks($qs)
    {    
    $query = $this->db->query("SELECT * FROM stocks WHERE description LIKE ('$qs%') ORDER BY description LIMIT 50");
    if($query->num_rows > 0)
        {
        foreach ($query->result_array() as $row)
              {
             $row_set[] = htmlentities(stripslashes($row['description']));
              }
             echo json_encode($row_set);
        }
     }


CONFIG SETTING/CSRF
Code:
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = FALSE;
$config['csrf_exclude_uris'] = array();

I HOPE the following code above can help. couse really don't know what should i do . . . and i think my autocomplete code are not the problem.
Reply
#5

Does the javascript console in your browser show the ajax requests going to the correct url?

What js library are you using for your autocompleter?

Are you sure it's sending via GET and not POST?
Reply
#6

What do you mean by : 


Does the javascript console in your browser show the ajax requests going to the correct url?

and use  http://jqueryui.com/download/  jquery-ui-1.11.3.custom library . . and yes it is get not post . . .
Reply
#7

If you're using jQuery UI, try:

Code:
$("#birds").autocomplete({
 source: function(request, response) {
   $.ajax({
     url: "/home/search_description",
     data: request,
     dataType: "json",
     type: "GET",
     success: function(data) {
       response(data);
     }
   });
 },
 minLength: 2,
 delay: 500
});

I took this from my currently working autocomplete code and just added in your info so adjust it as necessary. As for the console that CroNiX mentioned, open up Chrome, right click anywhere, and open up the inspector by clicking on "Inspect Element". Click on Console and you should be able see in real-time if your JS is really reaching out to your endpoint and if it's retrieving data correctly. Place console.log(data) in your JS code if you'd like to inspect your response in the console. If you're on Firefox, try the Firebug extension.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB