javascript - getting error when trying to use ajax with select2 -
any idea how debug ajax funtionality of select2? here's example of i'm trying implement: https://jsbin.com/sohupoviko/edit?html,output , here's result set http://localhost:4000/users:
[ { "id": 1, "first_name": "john", "last_name": "smith" }, { "id": 2, "first_name": "john2", "last_name": "smith2" } ] this local error being returned when run code locally:
jquery.min.js:2 jquery.deferred exception: cannot read property 'length' of undefined typeerror: cannot read property 'length' of undefined @ d (https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js:2:5214) @ object.f.transport.d.status.0.d.status.e.trigger.message (https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js:2:4227) @ j (http://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js:2:29948) @ k (http://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js:2:30262) undefined any idea root cause might or how debug?
in backend code please change query use "as text"
example:
$query = $mysqli->query("select id, first_name, last_name text users fist_name '%$term%'")); while ($row = mysql_fetch_assoc($query)) { $return[] = $row; } echo json_encode($return); credit goes -> select2.js error: cannot read property 'length' of undefined
Comments
Post a Comment