4
votes

I need to detect client side if a requested file (with XMLHttpRequest) had a 301 response. The reason of doing this is because I need to request other files related to the file where user has been redirected and not related to the first one requested. Any way to detect this response status code using JavaScript or JQuery?

Thanks.

2

2 Answers

3
votes

jQuery ajax callback function gives out a lot of info

$.ajax({
    url: "test.php",
    type: "GET",
    data: {},
    dataType:"json",
    success: function(resp, textStatus, xhr) {
        //status of request
        console.log(xhr.status);
    },
    complete: function(xhr, textStatus) {
        console.log(xhr.status);
    }
});
1
votes

You can use $.ajax with jquery

It has everything you need here : http://api.jquery.com/jQuery.ajax/

If you look at "statusCode" explaination, you will see you can make something for every code