如何实现 CloudSearch Amazon 和 Jquery 自动完成功能?</desc> <question vote="0"> <p>我在使用 Jquery 插件自动完成功能检索数据时遇到了问题。这是我的例子:</p> <pre><code><!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> </code></pre> <p>这是回应:</p> <pre><code>http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?&callback=jQuery11020041068303398787975_1421364823901&q=starwars&_=1421364823902 </code></pre> <p>这将附加所有字符串:</p> <pre><code>&callback=jQuery11020041068303398787975_1421364823901 </code></pre> <p>那是错误,那个字符串不是必需的。</p> <p>我需要这样的网址:</p> <pre><code>http://search-DOMAIN-iiwjjl6diqb7gluv2inqunahea.us-west-2.cloudsearch.amazonaws.com/2013-01-01/search?q=starwars </code></pre> <p>我需要一个 JSON 响应。</p> <p>我该怎么办?</p> </question> <answer tick="false" vote="0"> <p><strong>试试这个</strong></p> <pre><code>$.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); } </code></pre> </answer> </body></html>

问题描述 投票:0回答:0
javascript jquery amazon-cloudsearch
© www.soinside.com 2019 - 2024. All rights reserved.