php


Cannot get autocomplete to work in CodeIgniter - thoughts?


I have a form in which a user can type the name of a video game. What I'm trying to do is set up an autocomplete in a field with both a name and ID of "gameTitle." The autocomplete is to pull from a field called "title" from a database table called "aararity."
I used the guide on this blog as my paradigm.
First, I know for autocomplete to work, you need to have this in config/config.php and I do:
$config['csrf_protection'] = FALSE;
At the top of my view, I have:
$(document).ready(function() {
$(function() {
$( "#gameTitle" ).autocomplete({ // the field I want to autocomplete is called gameTitle
source: function(request, response) {
$.ajax({ url: "",
data: { term: $("#gameTitle").val()},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
minLength: 2
});
});
});
Here’s the “suggestions” function in my controller (the “title” referred to in $row->title refers to the “title” field in the database table I’m trying to pull from):
function suggestions()
{
$this->load->model('usergames_model');
$term = $this->input->post('term',TRUE);
if (strlen($term) < 2) break;
$rows = $this->autocomplete_model->GetAutocomplete(array('keyword' => $term));
$json_array = array();
foreach ($rows as $row)
array_push($json_array, $row->title);
echo json_encode($json_array);
}
Now, here’s what I added into the model:
function GetAutocomplete($options = array())
{
$this->db->select('title');
$this->db->like('title', $options['keyword'], 'after');
$query = $this->db->get('aararity');
return $query->result();
}
Basically, when I run the form, there’s no autocompletion whatsoever. I’m thinking the $options[keyword] parameter might be the problem; I pretty much copied that right from the aforementioned blog, and I’m guessing that might be a vague placeholder used by the author.
What am I missing?
OMG, I can't believe it...I figured it out...
suggestions() was trying to call a nonexistent model called "autocomplete_model" -- I forgot to change that to "usergames_model"!!!!
Now it works wonderfully!

Related Links

Do 'composer dump-autoload' with git
PHP: how to target base64 encoded messages?
PHP contact form issues
check google android subscription status on backend
phpMyAdmin Float Disable Round Number
Facebook Graph API Access Token Questions
Convert array to string with double quotes in php
Convolution filters (ie. “running average”) with Laravel's collections, functionally
How to remove controller name and action name from URL in Cakephp
Laravel - artisan commands return InvalidArgumentException
PHP: How to explode() string of Chinese Characters
PHP - Load variable page content
Can I generate registration token for GCM using my app server?
SQL, PHP export to CSV
URL Canonization Isuue, without www my website not working [closed]
How do i get the value of any one of the <tr> in a table when the table is made with a while ($row = $result->fetch_assoc()) command?

Categories

HOME
flask
user-interface
android-studio
facebook-messenger
dotnetnuke
qc
compilation
initialization
openlayers-3
histogram
google-sheets-query
hyperledger
repair
ag-grid
jpa-criteria
xamarin-zebble
match
colors
documentum
smooks
pm2
smartgwt
cuba-platform
twisted
web-deployment
codefluent
cpu-usage
significance
pfobject
raml
wsf
yii2-basic-app
stackexchange.redis
pymongo
intel
high-availability
jackrabbit-oak
onchange
phpstorm-2016.1
autoencoder
assertions
forms-authentication
best-buy-api
oauth2
imgur
netapp
spongycastle
dymola
kendo-treeview
yargs
clp
nvda
perforce-integrate
deferred-rendering
textblock
enunciate
m4
godeps
android-mapview
perceptron
variable-length-array
android-studio-import
domino-designer-eclipse
actionpack
whitespace-language
createfile
dmake
screwturn
incognito-mode
iosched
revmob
donut-chart
chefspec
navigationcontroller
differentiation
net-use
kernel32
simile
servlet-container
rawcontacts
main-method
inversion
sqlsitemapprovider
rakudo

Resources

Encrypt Message