POST ajax request not working with Cloudflare - Solved, the problem isn't cloudflare

Hi! When I try to send a POST request the site doesn’t get it, because the Cloudflare makes a redirect.
What is the problem, and how can I solve it?

1 Like

Cloudflare redirects things if you set up page rules to do so or if you turn on the " Always use HTTPS" setting… not sure if there are other cases where it redirects. Does it redirect if you POST the data over https? If so then it’s not due to “Always use HTTPS”.

I use https, and I don’t know what is the problem.
I have Always use HTTPS and Automatic HTTPS Rewrites

Do you have page rules that say to redirect? Are you sure Cloudflare is causing the redirect? What is it redirecting to/from?

It is refreshing the page (redirect it to itself) and because of that the POST request won’t be sent.
I have no page rules.

Are you sure Cloudflare is doing the redirect? Does it still happen if you disable the Cloudflare proxy :grey:?

It worked before the Cloudflare.
It is working with regular form but it isn’t with ajax.

Do you have a sample request that can reproduce the issue?
If you don’t want to share your own domain I don’t mind of you POST against my test domain:

If I make a form with post and submit it, it works perfectly.
But if I send the post via xhr it didn’t work. The server isn’t get the POST.

Can you make a curl that reproduces the issue?

Be aware that the curl might have sensitive info like cookies and stuff… You might want to strip out things that aren’t necessary to reproduce the issue.

Okay, it is working with curl and and jquery. Only not with xmlhttp request.

1 Like

If you can capture the actual request that has the problem it could make debugging this easier.
What about a .har file? If you can capture what is happening on the network level then you can look at what is different between jquery and xmlhttprequest. I think that would be helpful unless you think this is some kind of javascript api issue.

What about a If you can create a small snippet that recreates the problem then maybe I could help easier.

I think I will use jQuery. It is much better.
It’s just funny that a simple xmlhttprequest did not working.

I think there is something big problem with my code or site.
The test jquery post request page is working, xmlhttp isn’t but who cares?
But my other pages what does jquery post are not working. The site not get the post fields…
The codes are perfectly working on localhost or vps, without the Cloudflare.

You can use jquery on
What does the network tab in chrome show?
Did you ever get it working?

The problem was malformed post request. In a simple test it worked, but in normal it isn’t.
By the way in php://input it’s always working.

This topic was automatically closed after 14 days. New replies are no longer allowed.