Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an AJAX call, 302 is not followed

Tags:

I'm using jQuery 1.6.2 to make a POST AJAX request to a page on the same domain. That page does a 302 redirect to another page.

Now, on my local machine this work fine but on our production server, the redirect is never followed and in the Chrome inspector the request is said to be 'canceled'.

If I visit the same page without involving javascript, everything works fine, and as I said the AJAX works on my local machine but not on the production server.

Does anyone know what might cause this?

There are some differences between the servers (OS X, Apache2, PHP5.3.6, HTTP on local machine, Ubuntu, Lighttpd, PHP5.3.3, HTTPS on production) but none that to me should make any difference.

like image 765
Johan Avatar asked Aug 05 '11 11:08

Johan


People also ask

What is a 302 server error?

The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header.

How do I fix Error 302?

You can follow these five steps to fix HTTP 302 errors on your website: Determine whether the redirects are appropriate or not by examining the URLs that are issuing the 302 redirects. Check your plugins to make sure any redirect settings are valid. Ensure that your WordPress URL settings are configured correctly.

What happens during an AJAX call?

When you make an AJAX request, your browser sends an HTTP request to a given address. The server on the other end of the request responds, and returns the data to your browser. This is the same thing that happens when you navigate to a new web page.

Does AJAX follow redirect?

ajax appears to always follow redirects. How can I prevent this, and see the redirect without following it? There are various questions with titles like "jquery ajax redirect" but they all appear to involve accomplishing some other goal, rather than just directly checking the status that a server gives.


1 Answers

Turns out a bug in the redirect code caused the redirect to go to http:// while the page that was requested was https://. That makes the browser refuse to follow the redirect.

like image 119
Johan Avatar answered Sep 22 '22 08:09

Johan