Is it possible to get page redirect information via Ajax?

前端 未结 5 1028
眼角桃花
眼角桃花 2021-02-19 19:27

Without ajax, if we load http://example.com/1 and if it redirects to http://example.com/2 then the browser gets appropriate headers and the Browser URL

5条回答
  •  名媛妹妹
    2021-02-19 19:55

    Yes, when you request http://api.example.com using Ajax, browser does not redirect. You can get all the response using jQuery like bellow

    $.ajax({
        url: "http://api.example.com",
        success: function(data, textStatus, xhr) {
            console.log(xhr.status);
        },
        complete: function(xhr, textStatus) {
            console.log(xhr.status);
        } 
    });
    

提交回复
热议问题