Issue while returning ajax response

时间:2017-12-18 07:30:38

标签: php laravel function multidimensional-array

I want to return a url as ajax response.but before that I'am using an recursive funtion for flattening a multidimensional array keeping key.

 Log.d(getClass().getName(), "Your constant value "+Constant.your_value);

and recursive function is

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';
}

but now the 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; } array is being returned istead of $result

2 个答案:

答案 0 :(得分:0)

Remove time id lat lon type time 0 2121 2121 2121 2121 2121 1 2334 2334 2334 2334 2334 2 1523 1523 1523 1523 1523 6 8148 8148 8148 8148 8148 from your code,

display the text on the page using echo

print_r(Session::get('ezpay_response'))

答案 1 :(得分:0)

You should echo the url:

common

This is a full example.

Controller:

function response(){
    $resp_array = $this->flatten($trans_resp);
    //saving transaction response from  gateway to sessioion
    Session::push('ezpay_gateway_resp',json_encode($resp_array));
    echo '/gateway/success';
}

Route:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ExampleController extends Controller
{
   public function message()
   {
      $msg = "myurl/index";
      return response()->json(array('msg'=> $msg), 200);
   }
}

Javascript using it:

Route::get('ajax',function()
{
   return view('message');
});
Route::post('/msg','ExampleController@message');