Skip to content

Instantly share code, notes, and snippets.

@mox601
Created October 26, 2011 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mox601/1316255 to your computer and use it in GitHub Desktop.
Save mox601/1316255 to your computer and use it in GitHub Desktop.
autocomplete jquery configuration json response parsing
/* i added the ?callback=? part to the url because it is a cross-site request and it seems that with callback jquery is treating the request differently, not throwing an error */
var gaia_autocompletion_url = "http://hostname.eu:8080/web-service/suggest?callback=?";
var owner_id = 0;
var filter_status = "true";
function autocompleteFunction () {
$(this).autocomplete({
/*source function.
I need this to query a url with some named parameters and parse the JSON response
*/
source: function( request, response ) {
$.getJSON( gaia_autocompletion_url,
//GET parameter names and values
{
term: request.term,
owner: owner_id,
filter: filter_status
},
/* is it the callback function? */
/* Q: how am i supposed to just print and visualize the data of the response? */
function(data) {
console.log("data " + JSON.stringify(data.items));
}
);
console.log("response " + JSON.stringify(response));
},
minLength: minimumChars,
select: function( event, ui ) {
/* omitted code, no problems here, it works ok*/
} //end select
} //end parameters of autocomplete
);
}
/*
In chrome i get this error, I think when parsing the JSON
Uncaught SyntaxError: Unexpected token :
while in Firefox i get this other error:
invalid label
{"status":"OK","errorMessage":"","numb...,"label":"Basso continuo","owner":0}]}
*/
{"status":"OK","errorMessage":"","numberOfResults":10,"suggestions":[{"url":"http://dbpedia.org/resource/Bassiana","label":"Bassiana","owner":0},{"url":"http://dbpedia.org/resource/Julia_Soaemias_Bassiana","label":"Julia Soaemias Bassiana","owner":0},{"url":"http://dbpedia.org/resource/Julia_Bassiana","label":"Julia Bassiana","owner":0},{"url":"http://dbpedia.org/resource/Varius_Avitus_Bassianus_Marcus_Aurelius_Antoninus","label":"Varius Avitus Bassianus Marcus Aurelius Antoninus","owner":0},{"url":"http://dbpedia.org/resource/Bassianus_%28senator%29","label":"Bassianus (senator)","owner":0},{"url":"http://dbpedia.org/resource/Johannes_Bassianus","label":"Johannes Bassianus","owner":0},{"url":"http://dbpedia.org/resource/Julius_Bassianus","label":"Julius Bassianus","owner":0},{"url":"http://dbpedia.org/resource/Bassian_thrush","label":"Bassian thrush","owner":0},{"url":"http://dbpedia.org/resource/Bassianae","label":"Bassianae","owner":0},{"url":"http://dbpedia.org/resource/Bassian","label":"Bassian","owner":0}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment