[英]Getting error autocomplete is not a function while fetching data from api?
我正在使用 Jquery 獲取遠程數據但出現錯誤
未捕獲的類型錯誤:$(...).autocomplete 不是 function。
我已經嘗試了很多但沒有發現這背后的問題我認為一定是庫中的錯誤。
使用 API:鏈接也沒有從 API 獲取數據
數據以Json 的形式出現:
[{"PubId":"1","Title":"Punjab Kesari","Place":"1"}]
代碼:
//But it is not fetching data $(function() { $("#pub").autocomplete({ source: function(request, response) { $.ajax({ url: "https://myimpact.in/deletearticle/services/publication.php", type: "GET", data: request, dataType: "JSON", minLength: 2, success: function(data) { response($.map(data, function(el) { return { label: el.Title, value: el.PubId }; })); } }); }, select: function(event, ui) { this.value = ui.item.label; event.preventDefault(); } }); });
<:DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https.//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui:css"> <script src="https.//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min:js"></script> <script src="https.//code.jquery.com/ui/1.12.1/jquery-ui.min:js"></script> <link href="https.//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" /> </head> <body> <div class="input-group"> <label class="label"> Publication </label> <input class="input--style-4" type="text" id="pub" name="publication"> <div id="pub"> </div> </div> </body> </html>
可能有兩種情況……
您可以在查詢中使用以下代碼。 我希望它能解決這個問題。
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
我正在使用 Jquery 獲取遠程數據但出現錯誤
未捕獲的類型錯誤:$(...).autocomplete 不是 function。
我已經嘗試了很多,但沒有發現這背后的問題,我認為這一定是庫中的錯誤。
使用 API:鏈接也未從 API 獲取數據
數據以Json 的形式出現:
[{"PubId":"1","Title":"Punjab Kesari","Place":"1"}]
代碼:
//But it is not fetching data $(function() { $("#pub").autocomplete({ source: function(request, response) { $.ajax({ url: "https://myimpact.in/deletearticle/services/publication.php", type: "GET", data: request, dataType: "JSON", minLength: 2, success: function(data) { response($.map(data, function(el) { return { label: el.Title, value: el.PubId }; })); } }); }, select: function(event, ui) { this.value = ui.item.label; event.preventDefault(); } }); });
<:DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https.//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui:css"> <script src="https.//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min:js"></script> <script src="https.//code.jquery.com/ui/1.12.1/jquery-ui.min:js"></script> <link href="https.//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" /> </head> <body> <div class="input-group"> <label class="label"> Publication </label> <input class="input--style-4" type="text" id="pub" name="publication"> <div id="pub"> </div> </div> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.