如何实现 CloudSearch Amazon 和 Jquery 自动完成功能
How can I implement CloudSearch Amazon and Jquery autocomplete?
我在使用 Jquery 插件自动完成检索数据时遇到了问题。 这是我的例子:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Remote JSONP datasource</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<!-- <link rel="stylesheet" href="/resources/demos/style.css"> -->
<style>
.ui-autocomplete-loading {
background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat;
}
#city { width: 25em; }
</style>
<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#city" ).autocomplete({
source: function( request, response ) {
//$.getJSON('/http://search-profuturo-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?', { q: request.term }, function(data){ response(data); });
$.ajax({
url: "http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?",
dataType: "jsonp",
data: {
q: request.term
},
success: function( data ) {
response( data );
}
});
},
minLength: 3,
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" );
}
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="city">Your city: </label>
<input id="city">
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>
</body>
</html>
这是回应:
http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?&callback=jQuery11020041068303398787975_1421364823901&q=starwars&_=1421364823902
这将附加所有字符串:
&callback=jQuery11020041068303398787975_1421364823901
这是错误,该字符串不是必需的。
我需要这样 url:
http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?q=starwars
我需要一个 JSON 响应。
我该怎么办?
试试这个
$.ajax({
url: 'http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search',
data: {
q: 'starwars'
}
jsonp : false,
jsonpCallback: 'jsonCallback',
cache: 'true',
dataType: 'jsonp'
});
function jsonCallback(data) {
console.log(data);
}
相关文章:
- 重新启动游戏jQuery功能不工作
- 如何在iframe中激活jquery功能
- 为什么我不能使用jQuery功能
- 如何禁用缩略图的jquery功能
- 页面内容加载完毕后执行Jquery功能
- 按下空格键一次后,Jquery功能不起作用
- 单击滚动条时禁用Jquery功能
- 当屏幕大小小于480px时,如何禁用jQuery功能
- JQuery功能,可在任何地方增加字体大小
- 平移缩放 JQuery 功能
- jQuery功能,用于隐藏基于未在点击上运行的HTML5数据标签的元素
- 如何在循环中创建的多个按钮上使用相同的 jquery 功能
- 是否可以在更改单选按钮时禁用/启用jquery功能
- 如何使文本框值更改对 jQuery 功能生效
- 结合导航UL jQuery功能
- jQuery功能,根据粘贴文本时不起作用的字数限制文本输入
- mvc 4 jquery功能与dropdownlist和window.onload问题有关
- 固定导航条的JQuery功能不工作
- 单击导航选项卡时分配jQuery功能
- IE 11显示错误时,我点击jquery功能