我想返回一个url作为Ajax响应。但在此之前,我使用递归功能来展平保持键的多维数组。问题,同时返回ajax响应
function response(){
...
$response = Ezpay::PayWithToken($obj);
$trans_resp = json_decode(json_encode($response),true);
$resp_array = $this->flatten($trans_resp);
//saving transaction response from gateway to sessioion
Session::push('ezpay_gateway_resp',json_encode($resp_array));
print_r(Session::get('ezpay_response'))
return '/gateway/success';
}
和递归函数是
function flatten($array, $prefix = '') {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + $this->flatten($value, $key);
}
else {
$result[$key] = $value;
}
}
return $result;
}
但'/gateway/success'
在从哪儿获取'$ trans_resp'你的回应方法是什么? – linktoahref
$ response = Ezpay :: PayWithToken($ obj); $ trans_resp = json_decode(json_encode($ response),true); – Shalom
在'$ this-> flatten($ trans_resp)',其中''trans_resp'来自函数response()'。对不起如果我在以前的评论中不清楚 – linktoahref