我想返回一個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