Welcome Guest, Not a member yet? Register   Sign In
sending json using $this->output-set_output()

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),

->set_content_type(HTTP_CONTENT_TYPE_JSON->"constant we use")

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

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.

  'http://yoursite.com/some_controller/some_method',  //Url making request to
  function(data) {  //callback function
    console.log(data);  //data would be your json sent back from the controller

header('Content-type: application/json');
echo json_encode($response);

Plus what CroNiX stated above.

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

I think this is enough on the back-end
(encodes PHP objects and arrays into JSON format)
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)
$.getJSON(URL, function(data){

Theme © iAndrew 2016 - Forum software by © MyBB