4

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.

Manuel Bitto
  • 5,073
  • 6
  • 39
  • 47

2 Answers2

3

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);
    }
});
Siddhartha Gupta
  • 1,140
  • 8
  • 13
  • 3
    Looks like browser only receives 200 response. I can't see any 301 as xhr status even if that status is clearly displayed by chrome network inspector. – Manuel Bitto Jul 31 '13 at 12:44
1

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

Julien Rodrigues
  • 908
  • 2
  • 8
  • 18