Skip to content Skip to sidebar Skip to footer

Detect Http 301 Status Code From Javascript

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 whe

Solution 1:

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);
    }
});

Solution 2:

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

Post a Comment for "Detect Http 301 Status Code From Javascript"