in the implementation of the Amazon and Wikipedia Autocomplete API I am currently failing. Depending on the search parameter, another autocomplete service should be used. Unfortunately, none of the services work when Wikipedia (? Search = 5) is added. At Amazon API (?search=4) I only get to see the letters entered several times. I think both are the automatically displayed URL parameter "?callback=jSONXXXXXXXXX" blame.
Can you help me? The Google autocomplete works, but only if no other services like Amazon or Wikipedia are included.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet prefetch' href='https://rsms.me/inter/inter-ui.css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" type="text/css" />
<script src="//code.jquery.com/jquery-2.1.4.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js" type="text/javascript"></script>
<script>
if (window.location.search.indexOf('search=2') > -1) {
jQuery(function() {
jQuery( "#hyv-search" ).autocomplete({
source: function( request, response ) {
//console.log(request.term);
var sqValue = [];
jQuery.ajax({
type: "POST",
url: "http://suggestqueries.google.com/complete/search?hl=de&ds=yt&client=youtube&hjson=t&cp=1",
dataType: 'jsonp',
data: jQuery.extend({
q: request.term
}, { }),
success: function(data){
console.log(data[1]);
obj = data[1];
jQuery.each( obj, function( key, value ) {
sqValue.push(value[0]);
});
response( sqValue);
}
});
}
});
});
} else if (window.location.search.indexOf('search=3') > -1){
jQuery(function() {
jQuery( "#hyv-search" ).autocomplete({
source: function( request, response ) {
//console.log(request.term);
var sqValue = [];
jQuery.ajax({
type: "POST",
url: "http://suggestqueries.google.com/complete/search?hl=de&ds=sh&client=youtube&hjson=t&cp=1",
dataType: 'jsonp',
data: jQuery.extend({
q: request.term
}, { }),
success: function(data){
console.log(data[1]);
obj = data[1];
jQuery.each( obj, function( key, value ) {
sqValue.push(value[0]);
});
response( sqValue);
}
});
}
});
});
} else if (window.location.search.indexOf('search=4') > -1){
jQuery(function() {
jQuery( "#hyv-search" ).autocomplete({
source: function( request, response ) {
//console.log(request.term);
var sqValue = [];
jQuery.ajax({
type: "POST",
url: "https://completion.amazon.co.uk/search/complete?method=completion&mkt=4&p=Gateway&l=de_DE&b2b=0&fresh=0&sv=desktop&client=amazon-search-ui&x=String&search-alias=aps&ks=84",
dataType: 'jsonp',
data: jQuery.extend({
q: request.term
}, { }),
success: function(data){
console.log(data[1]);
obj = data[1];
jQuery.each( obj, function( key, value ) {
sqValue.push(value[0]);
});
response( sqValue);
}
});
}
});
});
} else if (window.location.search.indexOf('search=5') > -1){
jQuery(function() {
jQuery( "#hyv-search" ).autocomplete({
source: function( request, response ) {
//console.log(request.term);
var sqValue = [];
jQuery.ajax({
type: "POST",
url: "https://de.wikipedia.org/w/api.php",
jsonp : false,
jsonpCallback: 'jsonCallback',
// contentType: 'application/json', -- you can't set content type for a <script> tag, this option does nothing for jsonp | KevinB
cache: 'true',
dataType : 'jsonp'
data: jQuery.extend({
action: 'opensearch',
search: request.term
}, { }),
success: function(data){
console.log(data[1]);
obj = data[1];
jQuery.each( obj, function( key, value ) {
sqValue.push(value[0]);
});
response( sqValue);
}
});
}
});
});
} else {
jQuery(function() {
jQuery( "#hyv-search" ).autocomplete({
source: function( request, response ) {
//console.log(request.term);
var sqValue = [];
jQuery.ajax({
type: "POST",
url: "http://suggestqueries.google.com/complete/search?hl=de&client=youtube&hjson=t&cp=1",
dataType: 'jsonp',
data: jQuery.extend({
q: request.term
}, { }),
success: function(data){
console.log(data[1]);
obj = data[1];
jQuery.each( obj, function( key, value ) {
sqValue.push(value[0]);
});
response( sqValue);
}
});
}
});
});
}
</script>
and the HTML-Input...
<input id="hyv-search" class="ui-autocomplete-input" type="text" name="suche">
Greetings from Germany and thank you for your help!