gpt4 book ai didi

javascript - 自动完成 JQuery UI 不工作?

转载 作者:行者123 更新时间:2023-11-30 14:46:42 25 4
gpt4 key购买 nike

在 Amazon 和维基百科自动完成 API 的实现中,我目前失败了。根据搜索参数,应使用另一个自动完成服务。不幸的是,添加 Wikipedia (? Search = 5) 后,所有服务均无法使用。在 Amazon API (?search=4) 中,我只能看到多次输入的字母。我认为两者都是自动显示的URL参数“?callback=jSONXXXXXXXXX”惹的祸。

你能帮帮我吗? Google 自动完成功能有效,但前提是不包括其他服务,如亚马逊或维基百科。

    <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>

和 HTML 输入...

<input id="hyv-search" class="ui-autocomplete-input" type="text" name="suche">

来自德国的问候,感谢您的帮助!

最佳答案

wikipedia ajax 调用的 dataType : 'jsonp' 行之后,您缺少 ,。AND data:jQuery.extend({action: 'opensearch'},{search: request.term}), 而不是 数据:jQuery.extend({
行动:“开放搜索”,
搜索:request.term
}, { }),

并删除 jsonp : false,jsonpCallback: 'jsonCallback',

请在下面找到工作代码

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",
// 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);
}
});
}
});
});
}
<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>


<input id="hyv-search" class="ui-autocomplete-input" type="text" name="suche">

关于javascript - 自动完成 JQuery UI 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48800619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com