Failed to load http://example.com/signup.ashx: Redirect from 'http://example.com/signup.ashx' to 'http://0.0.0.0:8000/?result=success' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:8000' is therefore not allowed access.
How to make jquery
ajax
not follow the redirect after the successful form submission?
Basically my ajax
call is a success, but because of the CORS error ajax.fail()
is called instead of the ajax.done()
.
It seems that ajax
follow redirects transparently and that there were some considerations to add the methods allowing to override this behavior...
My code is really straightforward:
form.on("submit", function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: url,
data: data
}).done(function(data) {
// do something on success
}).fail(function(data) {
// do something on failure
});
});
It is a trivial task if one has access to both - the backend
as well as the frontend
, but it's quite a challenge if one has to deal with the remote API.
I do wonder, why on the 2nd decade of the 21th century (the time, when those other servers are just as important as our own) JQuery
still has this problem?