{"id":6367,"date":"2014-04-17T00:57:55","date_gmt":"2014-04-17T00:57:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/17\/passing-json-data-in-codeigniter-collection-of-common-programming-errors\/"},"modified":"2014-04-17T00:57:55","modified_gmt":"2014-04-17T00:57:55","slug":"passing-json-data-in-codeigniter-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/17\/passing-json-data-in-codeigniter-collection-of-common-programming-errors\/","title":{"rendered":"Passing JSON data in codeigniter-Collection of common programming errors"},"content":{"rendered":"<p>Greetings I have this statement that takes my array of results and echo&#8217;s it out to display on my AJAX form using json_encode, however now I want to pass the array as $data over to my Templatebuilder function since i&#8217;ll be using the search as part of a bigger template. This is the error i&#8217;m getting, for my ajax search. <strong>Undefined Variable: Results in ajax_search.php<\/strong><\/p>\n<p>This is all done within one controller.<\/p>\n<pre><code>if ( $this-&gt;input-&gt; is_ajax_request())\n    {\n        $this-&gt;output-&gt;set_header(\"Cache-Control: no-cache, must-revalidate\");\n        $this-&gt;output-&gt;set_header(\"Expires:Mon, 4 Apr 1994 04:44:44 GMT\");\n        $this-&gt;output-&gt;set_header(\"Content-type:application\/json\");\n\n        echo json_encode($results);\n\n    }\n<\/code><\/pre>\n<p>Then I wish to send the data to my templatebuilder with this statement:<\/p>\n<pre><code> echo $this-&gt;Templatebuilder('master', $data);\n<\/code><\/pre>\n<h2>this is my templatebuilder function<\/h2>\n<pre><code>private function Templatebuilder ($view, $data) {\n $master_data['page1'] = $this-&gt;load-&gt;view('page1', $data, true);\n $master_data['ajax_search'] = $this-&gt;load-&gt;view('ajax_search',  $data, true);\n return $this-&gt;load-&gt;view('master', $master_data, true);\n<\/code><\/pre>\n<p>and finally my ajax_search page<\/p>\n<pre><code>  \u2013\n                       \n                       \u2013\n                       \u2013\n                    \n\n\n                    \n\n\n\n            \n\n\n            \n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Greetings I have this statement that takes my array of results and echo&#8217;s it out to display on my AJAX form using json_encode, however now I want to pass the array as $data over to my Templatebuilder function since i&#8217;ll be using the search as part of a bigger template. This is the error i&#8217;m [&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-6367","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6367","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=6367"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6367\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}