I'm trying to do autosuggestion using solr along with jquery. For this I wrote the code below:
$(function() {
$( "#artist" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'http://localhost:8983/solr/terms?terms.fl=heading&terms.prefix='
+request.term+'&wt=json&json.nl=map',
dataType: "jsonp",
data: {
q: request.term,
rows: 10,
omitHeader: true,
},
success: function( data ) {
response( $.map( data.terms.heading, function( item ) {
return {
label: item,
value: item
}
}
)
);
}
});
},
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
I am getting the following error while running in Chrome
Uncaught SyntaxError: Unexpected token : The Json data I am getting is this
{"terms":{"heading":{"answer":24,"ansari":5}}}
I consulted the following link http://jqueryui.com/demos/autocomplete/#remote-jsonp but i am unable to find a solution. Please suggest what I am doing wrong
You've (correctly?) specified JSONP to access a Cross Origin resource, but you haven't told Solr that you want it to emit JSONP instead of pure JSON.
Add jsonp: 'json.wrf' to the parameters to $.ajax.
More at http://xplus3.net/2010/09/21/solr-and-jsonp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With