I am trying to return json from a module method. Very simple example at this point.

public function mealDates()
    echo "{\"foo\" : \"bar\"}";

From the template

    //request dates that are already taken
    type: "POST",
    url: "ACT=79",
    success: function(json){
    error: function(e){


If I declare dataType: 'json' returns error. If I don't I still am not getting the {"foo" :"bar"} from method. Suggestions on how to return json to template?


1 Answer 1


You can use send_ajax_response() which will return JSON and works well for response to ajax requests. For your example you'd do

public function mealDates()
    $array = array(
        'foo' => 'bar', 

    return $ee()->output->send_ajax_response($array);  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.