javascript - Select2 AJAX with JSON -
I am trying to populate my input with select2 using the provided JSON Here "JSON":
{"airport": [{"id": "1", "code": "AMQ", "city": "ambon", "country": "Indonesia"} "", "" "," 2 "," code ":" BJW "," city ":" barwa "," country ":" indonesia "}}} and HTML code:
input class = "" type = 'hidden' value = "192" data-init-text = 'departure city' name = 'Input' id = 'departure-airport' style = "width: 300px" /> and JS code:
$ ( Document) .ready (function () {$ ('# departure-airport'). Select2 ({min Interface length: 1, Ajax: {url: "http: // localhost: 4000 / Api / airports.json ", data type: 'jason', results: function (data) {return {result: data}}}}})}}; in console There is no error, but do I try to input them. It is always saying that "failed" or there is nothing. Data from JS never showed up. Do you have anything to fix it? There is a small mistake in jQuery:
$ (document) .ready (function () {$ ('# departure-airport'). Select2 ({minimumInputLength: 1, Ajax: {url: "http: // localhost: 4000 / api / airports.json", data type: 'jason', results: function (data) {// you have {results: data }, But your actual information is in the data. Airport {Results: data. Airports}}}}});}
Comments
Post a Comment