获取错误自动完成不是一个功能,而从api获取数据?



我使用Jquery获取远程数据,但得到错误

Uncaught TypeError: $(…)。自动补全不是一个功能

我已经尝试了很多,但没有发现背后的问题,我认为一定是一个错误在库。

使用API: link也不从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>

有两种情况…

  1. 您正在调用自动补全方法之前调用jQuery库。
  2. 另一个版本的jQuery包含在其他版本。

您可以在查询中使用以下代码。我希望这能解决问题。

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

最新更新