{"id":3483,"date":"2014-03-25T21:56:12","date_gmt":"2014-03-25T21:56:12","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/bootstrap-select2-unable-to-populate-via-ajax-collection-of-common-programming-errors\/"},"modified":"2014-03-25T21:56:12","modified_gmt":"2014-03-25T21:56:12","slug":"bootstrap-select2-unable-to-populate-via-ajax-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/bootstrap-select2-unable-to-populate-via-ajax-collection-of-common-programming-errors\/","title":{"rendered":"Bootstrap Select2 &#8211; Unable to populate via AJAX-Collection of common programming errors"},"content":{"rendered":"<p>I need some help figuring out what I am doing incorrectly. I am trying to populate the dropdown with users from my database. I am using Codeigniter and Firebug is giving me the error:<\/p>\n<p><code>TypeError: j is undefined<\/code><\/p>\n<p><strong>VIEW<\/strong><\/p>\n<pre><code> \n\n \n $(\"#users\").select2({\n        width: \"element\",\n        ajax: {\n            url: \"localhost\/index.php\/get_clients\",\n            dataType: 'json',\n            data: function (term, page) {\n                return {\n                    q: term\n                };\n            },\n            results: function (data, page) {\n                return { results: data };\n            }\n        }\n  });\n  \n<\/code><\/pre>\n<p><strong>CONTROLLER<\/strong><\/p>\n<pre><code>function get_clients() {\n    $this-&gt;load-&gt;model('users_model');\n    $result = $this-&gt;users_model-&gt;get_all_clients();\n }\n<\/code><\/pre>\n<p><strong>MODEL<\/strong><\/p>\n<pre><code> function get_all_clients() {\n    $all_clients = $this-&gt;db-&gt;select('CONCAT(first_name, \" \", last_name) as text, id', FALSE)\n    -&gt;get('clients')-&gt;result();\n    $rows = array();\n        foreach ($all_clients as $entry) {\n            $rows[] = $entry;\n        }\n        print json_encode($rows);\n}\n<\/code><\/pre>\n<p>Which returns something like this:<\/p>\n<pre><code>  [{\"text\":\"John Smith\",\"id\":\"433\"},{\"text\":\"Paul Sparks\",\"id\":\"434\"}]\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I need some help figuring out what I am doing incorrectly. I am trying to populate the dropdown with users from my database. I am using Codeigniter and Firebug is giving me the error: TypeError: j is undefined VIEW $(&#8220;#users&#8221;).select2({ width: &#8220;element&#8221;, ajax: { url: &#8220;localhost\/index.php\/get_clients&#8221;, dataType: &#8216;json&#8217;, data: function (term, page) { return { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3483","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3483"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3483\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}