Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pdxbenjamin's avatar

Half JS Half PHP 100% Laravel issue....

I'll start by linking my GIST . https://gist.github.com/pdxbenjamin/86b956e33699570da3d3f62fffa68a13

The issue is simple, I have a simple .ajax POST request in a js file. I have a simple function in a Controller. When I make my .ajax post request to the function in the Controller I get a 302 "Found" response header.

Why this is a problem for me? In the .ajax request always hits the ERROR switch, and I am unable to provide ajaxy feedback.

Does anyone know why that is happening, and how to fix it?

I'm trying to get this Stripe button working... if that helps. https://stripe.com/docs/checkout#integration-custom

Here are my Chrome Dev Tools Network tab results of a successful submission of the Stripe Button.

Where my .ajax post is going....

Request URL:http://localhost.dev/join
Request Method:POST
Status Code:302 Found
Remote Address:127.0.0.1:80

The page with a button...

Cache-Control:no-cache
Connection:keep-alive
Content-Type:text/html; charset=UTF-8
Date:Wed, 07 Dec 2016 03:25:52 GMT
Location:http://localhost.dev/register
Server:nginx/1.10.2

0 likes
4 replies
rdelorier's avatar

Do you get the same response if you include the accept header as application/json so laravel wont redirect if an error occurs?

pdxbenjamin's avatar

@rdelorier - Accept Header? I don't know what that is so I don't think I've tried that. What should I do?

pdxbenjamin's avatar

@rdelorier - I did the suggestions from your link, no joy. It's a weird situation. On the /register page I have a button that fires the .ajax with a POST to /join . Within the function join I have some logic for the Stripe situation but I found that the js .ajax post to /join never actually hits the function but redirects to /register ... or in my testing, whatever page / route I have the button loading off of. That's why i'm getting the 302 "Found" but redirected.

Please or to participate in this conversation.