sending json using $this->output-set_output() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: sending json using $this->output-set_output() (/showthread.php?tid=52678) |
sending json using $this->output-set_output() - El Forum - 06-20-2012 [eluser]Pet[/eluser] Hello there.I am actually running on this problem for days. I'm trying to send a json object to be handled by jquery $.get(). Here is the code for my controller. $data = array( // old //'feeds' => $this->_feeds(0, $group, $friend_id, NULL, NULL, NULL, $header), // new 'feeds' => $this->_feeds2($page = 0, $group, $friend_id, NULL, NULL, NULL, $header), 'owner_id' => $this->owner_id, 'friend_id' => $friend_id, 'group' => $group, 'type' => 'all', 'header' => $header, ); $json = array( 'error' => FALSE, 'html' => $this->page->template($data, 'fragments/feeds'->(view template), NULL->(content_path_on template), TRUE), ); $this->output ->set_content_type(HTTP_CONTENT_TYPE_JSON->"constant we use") ->set_output(json_encode($json)); } This code is just a templating engine we use. $this->page->template($data, 'fragments/feeds', NULL, TRUE) Ok so I send an output. How can I specify the output to my jquery or how can I capture this output on my jquery?...any ideas?.. TNX sending json using $this->output-set_output() - El Forum - 06-20-2012 [eluser]CroNiX[/eluser] If I'm understanding you, you can't just send something "to" jQuery. jQuery can make a request and have the server respond with some result which you can receive in the callback event of the $.get() request. Code: $.get( sending json using $this->output-set_output() - El Forum - 06-20-2012 [eluser]InsiteFX[/eluser] Code: header('Content-type: application/json'); Plus what CroNiX stated above. sending json using $this->output-set_output() - El Forum - 06-20-2012 [eluser]Pet[/eluser] tnx guys.... im too lazy to see i have to make that jquery function to load something out of json request. Big tnx Cronix InsiteFX sending json using $this->output-set_output() - El Forum - 06-20-2012 [eluser]CodeIgniteMe[/eluser] I think this is enough on the back-end (encodes PHP objects and arrays into JSON format) Code: echo json_encode($response); and on the front-end/javascript (ajax call for the URL and convert the response into JSON object. shorthand for $.ajax) Code: $.getJSON(URL, function(data){ |