Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

521
Vistas
Laravel: return data from server without redirect

What I'm trying to do is call function form server and validate data in javascript function but the return statement from server make redirect before response.complete("success")

button.onclick = async function handlePurchase() {
  const payment = new PaymentRequest(methods, details, options);
  try {
    const response = await payment.show();
    // Call server logic here and validate response if OK continue 
    // But server response redirect here so code not completed
    $('#checkout-form').submit();
    $.ajax({
    url: '{{route("apple-pay")}}',
      type: 'post',
      data: $('#checkout-form').serialize(),
      success: function(data){
          console.log('data :>> ', data);
      }
    });  
    await response.complete("success");
    // redirect to success page
  } catch (err) {
    console.error("Uh oh, something bad happened", err.message);
  }
}

Server function:

    public function pay(Request $request)
    {
        $merchant_id = env('CREDIMAX_MERCHANT_ID');
        $password = env('CREDIMAX_INTEGRATION_PASSWORD');

        $response = Http::withBasicAuth('merchant.'.$merchant_id, $password)->put
        ('https://example.com/api/rest/merchant/'.$merchant_id.'/order/1530/transaction/1', $data);

        return $respone->json();

     }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Seperate the request you are making to the third party app and the response you are sending back to you ajax call. This is how I mean:

public function pay(Request $request)
    {
        $merchant_id = env('CREDIMAX_MERCHANT_ID');
        $password = env('CREDIMAX_INTEGRATION_PASSWORD');

        $response = Http::withBasicAuth('merchant.'.$merchant_id, $password)->put
        ('https://example.com/api/rest/merchant/'.$merchant_id.'/order/1530/transaction/1', $data);

        return response()->json([
          'success' => $response->ok() ? 1 : 0,
          ...
        ]);

     }
over 4 years ago · Santiago Trujillo Denunciar

0

Check the last line in the controller it says "return $respone->json();" and should be "return $response->json();" -- missing the "s" in response.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda