I’ve managed to get a JSON output from my database for use with jQuery UI AutoComplete, and that’s working fine.
The trouble with it is, it seems the AutoComoplete plugin does all the parsing of JSON data for me, so I’m still to work out how that’s actually done.
I have a URL, http://test.hartnollguitars.co.uk/jsonOut/products.aspx?term=761294042656&barcode=yes (as an example) which gives me a single record from the same JSON output as I use for Autocomplete, I am trying to use this single record output for a single case.
So I’ve been Googling and messing around with jQuery getJSON, but I seem unable to get the info.
$.getJSON("jsonOut/products.aspx?barcode=yes", function () { alert(data.label); });
Is kind of where I’m at now, I know this is wrong and I have tried various other permutations of this code following examples from the jQuery site, but I just can’t get the output I need.
It’s obviously because I’ve got no idea what I am doing, but can someone just explain how you:
- Get data from a single record like this
- Get data from a series of data and loop through to display the output (for example from an FQL output from the Facebook Graph for a simple object such as events)
All help much appreciated!
Remeber to use an absolute url, not a relative. The code you have pasted will append the url to the current directory, so it will only work if it is coming from
/.The JSON being returned is an array, so you have to dereference an element:
or the more useful thing to do would be: