s = s.toLowerCase(); // "s is undefined" - jQuery 1.4.4
Closed this issue · 14 comments
I'm having an issue with jQuery 1.4. The first search I run works great, the second one says "s is undefined". Looking into this I"m having a hard time determining what's going wrong. the json I'm using is here: http://asdfj34j.pastebin.com/b3xfS1A0
The code I'm using to initialize the autocomplete is here: http://asdfj34j.pastebin.com/dE4PbSmH
Thanks again for supplying this plugin. We don't want to use the jQuery UI because it's too bloated with stuff we'll never use.
Hi, bkuhl. I see that the fccid item is undefined in most of JSON blocks. Have you tried using JSON data that doesn’t include undefined items, just to rule that out?
Also, if you get a chance, let me know what the path error path looks like on your console. The piece of code you included in the title refers to a line inside the matchSubset function, but this function gets called a few times in the plugin, so knowing which instance of the function fed it data that resulted in the s var to be undefined would be very helpful.
Thanks!
Thanks for the quick response...
I'll rule out the undefined items tomorrow morning
s is undefined matchSubset(s=undefined, sub="for 010")autocomplete.js (line 455) (?)(i=0, x=Object { data={...}})autocomplete.js (line 574) noop(a=[Object { data={...}}, Object { data={...}}, Object { data={...}}, 21 more...], b=function(), d=Object { data={...}})jquery....min.js (line 30) load(q="for 010")autocomplete.js (line 573) request(term="for 010", success=receiveData(q, data), failure=hideResultsNow())autocomplete.js (line 360) onChange(crap=31, skipPrevCheck=undefined)autocomplete.js (line 270) [Break On This Error] s = s.toLowerCase();
Which version of the Autocomplete Plugin are you using? Those line numbers don’t correspond to the line numbers the code appears on in v 1.2. Have you added code to the plugin?
The plugin is not a standalone file... I moved it to it's own file so the line numbers match up....
s is undefined matchSubset(s=undefined, sub="for ")autocomplete.js (line 444) (?)(i=0, x=Object { data={...}})autocomplete.js (line 563) noop(a=[Object { data={...}}, Object { data={...}}, Object { data={...}}, 93 more...], b=function(), d=Object { data={...}})jquery....min.js (line 30) load(q="for ")autocomplete.js (line 562) request(term="for ", success=receiveData(q, data), failure=hideResultsNow())autocomplete.js (line 349) onChange(crap=-10, skipPrevCheck=undefined)autocomplete.js (line 259) [Break On This Error] s = s.toLowerCase();
Hi, bkuhl. I’ve been MIA for most of the Holidays. Did you manage to resolve this issue? Let me know if you still need help with it. Thanks!
That's fine, we've all been busy around the holidays. I'll have to check tomorrow morning for you when I get to work, thanks!
I've uploaded a sample here: http://beta dot ikeyless dot com/aftermarket/search/
If you do a search for "EZS" then add "D" after the autocomplete shows up it throws "s is undefined"
This is using 1.4.4 not 1.4.2 like I initially thought which explains the issue.
Hi, bkuhl.
After looking at this for a while, I realize that you’re using an outdated version of the plugin (1.1pre). I suggest you update your script to one of the following:
Jörn Zaefferer’s last version of the plugin before deprecating it (1.1);
Dylan Verheul’s update to Jörn’s original; or
My version with a couple of updates I found necessary for my projects (1.2).
Let me know if your issue is resolved by updating the plugin.
I've updated, unfortunately it didn't fix the issue :-\
On the sample at beta dot ikeyless? I see the same 1.1pre plugin there.
Sorry about that, I have another copy on our internal systems which is where I'm also experiencing the problem. The internal system was on 1.2. I've updated beta.ikeyless to have 1.2 as well.
Hi, bkuhl. I may have found what was causing this bug.
When data is coming from a json feed via url, the script requires x.value to be defined, and not just its .data, meaning that when you parse the json (in the extra params you’re sending the plugin in line 11 of your search.js file), you need to do the following:
parse: function(data) {
var array = new Array();
for(var i=0;i<data.items.length;i++) {
array[array.length] = {
data: data.items[i],
value: data.items[i]
};
}
return array;
},
You’ll notice that I added the value: data.items[i]
pair to the object pushed to the array.
I’m not entirely sure why this is, as I didn’t write this part of the code and my knowledge of JS is limited, but after reproducing your problem on my end, I was able to fix it with the above change.
Let me know how this works out for you!
You're the man!! That was it... though for me "data.items[i]" was an object, so I had to make it a string for everything to work properly. Works out great though, thanks so much for the help, I really appreciate it!!
Hey, no problem. We’re all learning as we go. :)