Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  129] [ 1]  / answers: 1 / hits: 29828  / 15 Years ago, mon, november 16, 2009, 12:00:00

I need to encode a javascript function into a JSON object in PHP.



This:



$function = function(){};
$message = Hello;

$json = array(
'message' => $message,
'func' => $function
);
echo json_encode($json);


outputs:



{message:Hello,func:function(){}}


What I want is:



{message:Hello,func:function(){}}


Can I do this with json_encode?


More From » php

 Answers
183

As Jani said, this is not possible directly with JSON, but this might help you: http://web.archive.org/web/20080828165256/http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/


[#98299] Thursday, November 12, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juliettec

Total Points: 327
Total Questions: 127
Total Answers: 102

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
;