jstayton / jquery-marcopolo

A jQuery autocomplete plugin for the discerning developer.
http://jstayton.github.io/jquery-marcopolo
MIT License
179 stars 27 forks source link

json validity question #12

Closed matthewstokeley closed 12 years ago

matthewstokeley commented 12 years ago

hey, thanks so much for this plugin, it really seems to be a well thought out approach to the autocompletion pattern. i know this isn't support so feel free to delete, however ....

in the documentation, the json reads :
first_name: 'James', last_name: 'Butler', profile_url: '/users/78749',

however, i'm pulling my json from a mssql database, giving it a utf-8 header and outputting valid json as

"ID": 1,
"Department": "Assembly",
"Manager": "eh",

is this discrepancy between the json and string handling with quotes the reason why mp is connecting to the url, sending the param but not being sent back any data?

my js:

$('#customer').marcoPolo({
url: '../modules/quality-control-dependencies/quality-control-live-search-departments.php',
formatItem: function (data, $item) { 
return data.department;
},
onSelect: function (data, $item) {
this.val(data.department);
},
minChars: 3
});
jstayton commented 12 years ago

Hey, thanks for the kind words! Means a lot.

Your JSON is actually more valid than the JSON in the documentation, now that I'm looking at it. (I'll fix that.)

If you browse directly to the URL Marco Polo is requesting, do you get data back? Can you post the exact data back here? That'll help in troubleshooting.

Justin

matthewstokeley commented 12 years ago

thanks so much for the help Justin.

my bloated url is quality-control-live-search-departments.php?u=Assembly

json:

[{"ID":1,"Department":"Assembly","Manager":"EF"}]   

i'm fairly sure mp is connecting to the page, as i'm not getting the error message. thanks again!

jstayton commented 12 years ago

Your JSON is valid, but you're using data.department instead of data.Department in the callback methods (case-sensitivity is important). Give that try and let me know if it works. Thanks!

Justin

matthewstokeley commented 12 years ago

Hey Justin, I did see that after I posted it and changed it, however still no dice. Really appreciate the help though!

jstayton commented 12 years ago

Do you have access to developer tools (or Firebug) in the browser you're using? Are you getting any JavaScript warnings/errors? Can you put console.log(data); in your formatItem callback and see what's output?

matthewstokeley commented 12 years ago

I'm not getting any errors except the character minimum restriction. After three characters, I get an ok get but a null response. Perhaps its the fact that this is hosted on a windows server, even if I am adding json headers via php.

jstayton commented 12 years ago

Hmmm, yeah, an empty response is hard to diagnose since there are so many possibilities. I don't think I'll be of much help on that end. Once you do figure it out and start getting the proper JSON response, let me know if you continue to experience problems on the Marco Polo side.

Justin

matthewstokeley commented 12 years ago

Thanks so much for your help and for making the best autocomplete plugin bar none. For the sake of anyone looking this over and having the same problem as me, simply renaming the param made it work. Not sure why, but happy it does. Thanks again!