[jQuery] Re: [Autocomplete] - Doesn't always work

2009-05-19 Thread Shawn


There are a few different autocomplete plugins out there.  I'll assume 
you are using the one found at 
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/  (which 
is the one documented at docs.jquery.com)  The author, Jorn Zaefferer, 
is on this list often


I've seen oddities like this with the plugin, but it pretty much always 
was a problem in how I was implementing the plugin.  Or a potential 
problem with my server side code or local network.  But I tend to do 
more than the absolute basics too, so I always assume it's my fault 
first.. :)


Short of seeing some sample code, I'm not sure how much more I can help 
out... But hope that points you towards the solution somewhat.


Shawn

MeanStudios wrote:

Greetings,

I'm currently using this awesome plugin for my web app but I'm having
a bit of an annoying bug with it.  It sometimes does not pull up any
results when typing in.  Like if I have something in the database with
the name March and I type in mar it shows the little loading.gif
but then disappears and doesn't give me any results.  If I tab away
and come back to it and try it again, then it will work.  And even
that doesn't make it work.  Sometimes I have to totally refresh the
page.  I thought it might be the cache mechanism so I turned that off
setting cacheLength to 1.
Any other ideas as to why it sometimes works and sometimes doesn't?


[jQuery] Re: [Autocomplete] - Doesn't always work

2009-05-19 Thread MeanStudios

Shawn, yes, that is the plugin I am talking about.  In Jorn's blog
post on Autocomplete he said to post here with [Autocomplete] in the
subject if having problems.

Here's the code I'm using:

$(#client_name).autocomplete(/ac/get_clients/, {
scroll: true,
scrollHeight: 300,
autoFill: true,
cacheLength: 1,
max: 20,
matchContains: false
});

I also have a .result(function(){}); running after that as well so I
can populate a form with the returned data from the autocomplete.
I'm using CodeIgniter as my php framework utilizing a library called
DataMapper which is an implementation of an ORM.  Here's the function
I'm using to return the data:

function get_clients()
{
$c = new Client();
$c-get();
$q = strtolower($_POST['q']);
if ( ! $q)
return;
foreach ($c-all as $client) {
if (strpos(strtolower($client-name), $q) !== false) {
echo $client-name|$client-id\n;
}
}
}

On May 19, 5:36 pm, Shawn sgro...@open2space.com wrote:
 There are a few different autocomplete plugins out there.  I'll assume
 you are using the one found 
 athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ (which
 is the one documented at docs.jquery.com)  The author, Jorn Zaefferer,
 is on this list often

 I've seen oddities like this with the plugin, but it pretty much always
 was a problem in how I was implementing the plugin.  Or a potential
 problem with my server side code or local network.  But I tend to do
 more than the absolute basics too, so I always assume it's my fault
 first.. :)

 Short of seeing some sample code, I'm not sure how much more I can help
 out... But hope that points you towards the solution somewhat.

 Shawn

 MeanStudios wrote:
  Greetings,

  I'm currently using this awesome plugin for my web app but I'm having
  a bit of an annoying bug with it.  It sometimes does not pull up any
  results when typing in.  Like if I have something in the database with
  the name March and I type in mar it shows the little loading.gif
  but then disappears and doesn't give me any results.  If I tab away
  and come back to it and try it again, then it will work.  And even
  that doesn't make it work.  Sometimes I have to totally refresh the
  page.  I thought it might be the cache mechanism so I turned that off
  setting cacheLength to 1.
  Any other ideas as to why it sometimes works and sometimes doesn't?


[jQuery] Re: [Autocomplete] - Doesn't always work

2009-05-19 Thread Shawn


I don't see anything tooo odd here.  Here's what I would suggest though:

1. Call the autocomplete function a few times manually.  Put the URL to 
it in the browser's address bar and load the page a few times (you'll 
need to switch your code to use $_GET though).  Try to mix up the speed 
of reloads, the data being passed, etc.  IF you see any blank pages, 
then you know the server side code is where the problem is at.  But if 
you always see output, continue debugging


2. Temporarily remove the .result() method just to ensure that is not 
causing confusion somewhere.  Commenting it out should be good enough.


3. Make sure you are using the most recent stable version of the plugin.

4. In your PHP code, where you are checking for no 'q' value and just 
exit the function replace that return with something like


  echo no criteria|0;
  return;

Just to see if this condition is the problem area.  Also, I'd probably 
change the condition to be   if (empty($q))  - which is a slightly 
better check.  That's a style thing though, so up to you


Now, with that out of the way...  Your PHP code seems odd to me.  Why 
pull back ALL clients and then do a string comparison to sort out what 
to show or not?  It is MUCH faster/more efficient to let the database do 
that filtering for you.  Do you have control of the Client class?  If 
so, can you add a search method that takes the 'q' value as a criteria 
for the name?  But, the code as is *should* run, so take my comments as 
constructive observations... :)


Shawn

MeanStudios wrote:

Shawn, yes, that is the plugin I am talking about.  In Jorn's blog
post on Autocomplete he said to post here with [Autocomplete] in the
subject if having problems.

Here's the code I'm using:

$(#client_name).autocomplete(/ac/get_clients/, {
scroll: true,
scrollHeight: 300,
autoFill: true,
cacheLength: 1,
max: 20,
matchContains: false
});

I also have a .result(function(){}); running after that as well so I
can populate a form with the returned data from the autocomplete.
I'm using CodeIgniter as my php framework utilizing a library called
DataMapper which is an implementation of an ORM.  Here's the function
I'm using to return the data:

function get_clients()
{
$c = new Client();
$c-get();
$q = strtolower($_POST['q']);
if ( ! $q)
return;
foreach ($c-all as $client) {
if (strpos(strtolower($client-name), $q) !== false) {
echo $client-name|$client-id\n;
}
}
}

On May 19, 5:36 pm, Shawn sgro...@open2space.com wrote:

There are a few different autocomplete plugins out there.  I'll assume
you are using the one found 
athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ (which
is the one documented at docs.jquery.com)  The author, Jorn Zaefferer,
is on this list often

I've seen oddities like this with the plugin, but it pretty much always
was a problem in how I was implementing the plugin.  Or a potential
problem with my server side code or local network.  But I tend to do
more than the absolute basics too, so I always assume it's my fault
first.. :)

Short of seeing some sample code, I'm not sure how much more I can help
out... But hope that points you towards the solution somewhat.

Shawn

MeanStudios wrote:

Greetings,
I'm currently using this awesome plugin for my web app but I'm having
a bit of an annoying bug with it.  It sometimes does not pull up any
results when typing in.  Like if I have something in the database with
the name March and I type in mar it shows the little loading.gif
but then disappears and doesn't give me any results.  If I tab away
and come back to it and try it again, then it will work.  And even
that doesn't make it work.  Sometimes I have to totally refresh the
page.  I thought it might be the cache mechanism so I turned that off
setting cacheLength to 1.
Any other ideas as to why it sometimes works and sometimes doesn't?


[jQuery] Re: [Autocomplete] - Doesn't always work

2009-05-19 Thread MeanStudios

Thank you very much for your reply! Lots of great ideas :).

I will let you know how it all turns out.

As for using the database to do the filtering, that is a great idea!
Yes, I have full control over the client class so it shouldn't be a
problem.

Best Regards!

On May 20, 7:45 am, Shawn sgro...@open2space.com wrote:
 I don't see anything tooo odd here.  Here's what I would suggest though:

 1. Call the autocomplete function a few times manually.  Put the URL to
 it in the browser's address bar and load the page a few times (you'll
 need to switch your code to use $_GET though).  Try to mix up the speed
 of reloads, the data being passed, etc.  IF you see any blank pages,
 then you know the server side code is where the problem is at.  But if
 you always see output, continue debugging

 2. Temporarily remove the .result() method just to ensure that is not
 causing confusion somewhere.  Commenting it out should be good enough.

 3. Make sure you are using the most recent stable version of the plugin.

 4. In your PHP code, where you are checking for no 'q' value and just
 exit the function replace that return with something like

    echo no criteria|0;
    return;

 Just to see if this condition is the problem area.  Also, I'd probably
 change the condition to be   if (empty($q))  - which is a slightly
 better check.  That's a style thing though, so up to you

 Now, with that out of the way...  Your PHP code seems odd to me.  Why
 pull back ALL clients and then do a string comparison to sort out what
 to show or not?  It is MUCH faster/more efficient to let the database do
 that filtering for you.  Do you have control of the Client class?  If
 so, can you add a search method that takes the 'q' value as a criteria
 for the name?  But, the code as is *should* run, so take my comments as
 constructive observations... :)

 Shawn

 MeanStudios wrote:
  Shawn, yes, that is the plugin I am talking about.  In Jorn's blog
  post on Autocomplete he said to post here with [Autocomplete] in the
  subject if having problems.

  Here's the code I'm using:

  $(#client_name).autocomplete(/ac/get_clients/, {
     scroll: true,
     scrollHeight: 300,
     autoFill: true,
     cacheLength: 1,
     max: 20,
     matchContains: false
  });

  I also have a .result(function(){}); running after that as well so I
  can populate a form with the returned data from the autocomplete.
  I'm using CodeIgniter as my php framework utilizing a library called
  DataMapper which is an implementation of an ORM.  Here's the function
  I'm using to return the data:

  function get_clients()
  {
     $c = new Client();
     $c-get();
     $q = strtolower($_POST['q']);
     if ( ! $q)
             return;
     foreach ($c-all as $client) {
             if (strpos(strtolower($client-name), $q) !== false) {
                     echo $client-name|$client-id\n;
             }
     }
  }

  On May 19, 5:36 pm, Shawn sgro...@open2space.com wrote:
  There are a few different autocomplete plugins out there.  I'll assume
  you are using the one found 
  athttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/(which
  is the one documented at docs.jquery.com)  The author, Jorn Zaefferer,
  is on this list often

  I've seen oddities like this with the plugin, but it pretty much always
  was a problem in how I was implementing the plugin.  Or a potential
  problem with my server side code or local network.  But I tend to do
  more than the absolute basics too, so I always assume it's my fault
  first.. :)

  Short of seeing some sample code, I'm not sure how much more I can help
  out... But hope that points you towards the solution somewhat.

  Shawn

  MeanStudios wrote:
  Greetings,
  I'm currently using this awesome plugin for my web app but I'm having
  a bit of an annoying bug with it.  It sometimes does not pull up any
  results when typing in.  Like if I have something in the database with
  the name March and I type in mar it shows the little loading.gif
  but then disappears and doesn't give me any results.  If I tab away
  and come back to it and try it again, then it will work.  And even
  that doesn't make it work.  Sometimes I have to totally refresh the
  page.  I thought it might be the cache mechanism so I turned that off
  setting cacheLength to 1.
  Any other ideas as to why it sometimes works and sometimes doesn't?