On 22 okt, 00:37, James <james.gp....@gmail.com> wrote: > try this: > > $data = array('votes_for'=>7, 'votes_against'=>4); > echo json_encode($data); > exit;
Hi James, Thanks for your response but I managed to solve my problem in a different way. I said in my first post the view doesn't always know on forehand what format to expect (sometimes JSON data, other times a boolean) and that therefore I had to use jQuery.get instead of jQuery.getJSON. What I changed is the format in which I return data. I now always return a JSON object, which makes more sense. To illustrate what I mean, here are the two different formats of resulted data. scenario 1: vote succeeded. $vote_response = array( "status" => "success", "voted" => $_GET["vote"], "num_votes" => array( "votes_for" => 7, "votes_against" => 4 ) ); scenario 2: vote failed. $vote_response = array( "status" => "fail", "message" => "you cannot make the same vote twice" ); Regards, Maarten