How do I get JSON data (sent by ‘func2’) in ‘func1’?
func1.php
include 'func2.php';
$data = run_method();
func2.php
function run_method() {
//...
echo json_encode(array('f1' => $val1, 'f2' => $val2));
die();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need not to
echobut toreturndata like:UPD:
To see what you get in
$datausevar_dump($data);after$data = run_method();In
func1.phpyou have to decode json_encoded data back (unserialize it).So the best way here is not to use
json_encodeand return simple array like:In your case to access
$val1use$data['f1'], to access$val2use$data['f2'].