Just by doing Select2
hello-world exercises I cannot load ajax
data, but rather getting an error:
Uncaught TypeError: c.ajax is not a function
at Object.transport (select2.min.js:1)
at d (select2.min.js:1)
My code:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#my-input').select2({
placeholder: "Search for something",
minimumInputLength: 1,
ajax: {
url: "https://www.example.com/search",
dataType: 'json',
delay: 250,
data: function(params) {
return {
"term": params.term, // search term
"from": 0,
"size": 20
};
},
processResults: function (data, params) {
params.page = params.page || 1;
data.hits = $.map(data.hits, function(obj) {
obj.text = obj.text || obj.name;
return obj;
});
return {
results: data.hits,
};
},
cache: true
}
});
});
</script>