1

I have tag html like this:

<input type="text" name="KELOLA_NAMA_RM" value="" maxlength="100" size="30" />

And i want to add fiture in the input text using autocomplete.

The code like this:

$('#KELOLA_NAMA_RM').autocomplete({
    source: "<?php echo $getDataLaporan;?>",
    minLength: 1    
});

And controller PHP like this:

    public function getLaporan(){
    echo 'justtesting';
    exit;
}

When i try to check console in firebug, i get an error like this: enter image description here

i call the getDataLaporan in controller like this:

$data['getDataLaporan'] = base_url().index_page()."/rm/getLaporan";

How can i get result 'justtesting' in the autocomplete?

user3505775
  • 339
  • 2
  • 6
  • 20
  • Your selector is using an id while you have a name. Try `id="KELOLA_NAMA_RM"` in your input. – Neoares Dec 10 '15 at 13:58
  • show us how you are calling the controller. – Mohammad Dec 10 '15 at 14:00
  • @Neoares i am sorry, i forget to add the id in the post. In my real code, i have inputed id in the code. – user3505775 Dec 10 '15 at 14:01
  • @Mohammad i have updated my post, please check again. – user3505775 Dec 10 '15 at 14:03
  • @user3505775 why the requested url contains a variable `t=term` ?! please go to ur function url without this term and tell us what did you get. – Mohammad Dec 10 '15 at 14:18
  • @Mohammad because when you use jquery form, the data will use get method and using term as variable to pass the data. That's why i post to stackoverflow to ask how can i get the 'justtesting' when i use that code. because when i use ajax, and using post method, i can get the method, but when i use autocomplete, the url can't find the method – user3505775 Dec 10 '15 at 14:21

1 Answers1

0

I'm assuming you are using jqueryui so look at the docs for autocomplete. [https://jqueryui.com/autocomplete/#default] You need to pass it a javascript array. So, if you are going to echo out the data then you need format it properly into an array. You can tell if you got it right by viewing source.

Your php doesn't really make much sense. You have a function that echos (it probably should return the data) and you don't show how the function is being used or how $getDataLaporan is getting declared. You then echo the function that doesn't return any data.

You should look at using a remote data source it will probably be easier/cleaner.

https://jqueryui.com/autocomplete/#remote

hendr1x
  • 1,470
  • 1
  • 14
  • 23