Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

523
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda