Get back link that it has been redirected to

$.ajax({
	url: "item.php?go=" + myValue,
	type: "GET",
       	success: function(data) {
	},
	error: function(data) {
	}
});

Is pretty basic. I go to item.php with my value. The thing is that item.php redirects user to index.php?qwe=1 with PHP’s Location(); when it’s wrong (which is not the point why, script decides so). I need to treat this redirection as 404. Meaning that I need to execute either error: function [...] or itFailed() function. When script is being redirected to this page.

Any recommendations?

Short story: script requests data, but get rightfully redirected to our error non-404 page if something is wrong, I need to see when it’s redirected, so I that it’s wrong.

you can use the statusCode callbacks to do something when a certain status code is sent, but AJAX will still follow the redirect. So I assume that using the success/error settings can’t be used at all in your situation.

Could I send a specific header (that I could set in JavaScript item.php) that would be received through AJAX and seen?

AJAX receives every header you send. not sure what you mean by ‘seen’, though.

I guess I’ll have to go another way.

Are you sure there no way of asking “What page have I landed on after everything?” that would seem like crucial part.

It seems to be returning content of the site it’s been redirected on, are you sure you really can’t get the “current location” of now?

that would be the one you receive in the success handler.

Obviously, that’s what HTTP clients are supposed to do, otherwise there were no point in HTTP headers.

As I previously said, hook into jQuery’s status code events.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.