We have two domains(xyz.com and zxy.com). and using jquery ajax call to get the data from one domain.
If first one fails, how do i check and redirect to another domain using javascript.
We have two domains(xyz.com and zxy.com). and using jquery ajax call to get the data from one domain.
If first one fails, how do i check and redirect to another domain using javascript.
Could you not just use window.location.host
to find out which domain the user is currently on?
This way you can make the correct ajax call from the start. There is no reason to make a request to the wrong domain, wait for it to fail then make another request.
If you do however wish to actually make an AJAX
request and wait for it to fail then make a different request it would be as follows (this answer is quite verbose on purpose):
var firstRequest = $.ajax({
url: 'http://xyz.com',
timeout: 5000
});
firstRequest.done(function (data) {
});
firstRequest.fail(function () {
var anotherRequest = $.ajax({
url: 'http://xzy.com',
timeout: 5000
});
anotherRequest.done(function (data) {
});
anotherRequest.fail(function () {
});
});