2
I have a code that redirects an AJAX request and it works normally on localhost, but on the hosting server cross-browser the request is not redirected.
header('Location: http://dominio.com/endereco');
exit;
Blocking request forwarding AJAX is standard?
Is there any code to enable such redirection?
May contain error in my code?
I make the request using jQuery.ajax:
$.ajax({
url: "http://dominio.com/controller/action",
data:dados,
dataType: "json",
success: Sucesso,
error: Erro
})
These are different domains, where you are running ajax and redirect domain?
– Luizz
because you don’t use JS to redirect,
location.href ='http://dominio.com/endereco'
– Luizz
Make PHP return by JSON or the URL value only so that the client-side link is redid
– Giancarlo Abel Giulian
These are different sub-domains, for example:
http://api.dominio.com
andhttp://teste.api.dominio.com
– KaduAmaral
I cannot redirect via Javascript because I am building an API, and this redirection is part of the API rule and not the consumer’s rule.
– KaduAmaral
As far as I know, browsers block AJAX requests out of the site making the request. This is for security and you may have an exception if the URL is localhost. Try to confirm if this is not the problem, and see the code returned by the function in inspecting.
– Clayderson Ferreira
That’s probably it, I talked to a college professor and he commented that this could be a default setting for browsers, where a request cross-Domain cannot be redirected for security reasons.
– KaduAmaral