Is it possible to retrieve http response status?

Discussion in 'Javascript' started by Khai Doan, May 22, 2008.

  1. Khai Doan

    Khai Doan Guest

    I am using Selenium, a javascript framework for automated testing of
    web application. The problem occurs when there is a server side HTTP
    redirect. Selenium would detect that a new page is loaded, proceed to
    the next command which then fail because the browser is carrying out
    the redirect. So, is it possible to use javascript on the browser
    side (Firefox 2) to get the http response status code?
    Khai Doan, May 22, 2008
    #1
    1. Advertising

  2. Khai Doan wrote:
    > I am using Selenium, a javascript framework for automated testing of
    > web application. The problem occurs when there is a server side HTTP
    > redirect. Selenium would detect that a new page is loaded, proceed to
    > the next command which then fail because the browser is carrying out
    > the redirect. So, is it possible to use javascript on the browser
    > side (Firefox 2) to get the http response status code?


    If you use XMLHttpRequest to make an HTTP request then you can read out
    the status and statusText properties:
    http://developer.mozilla.org/en/docs/XMLHttpRequest



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 22, 2008
    #2
    1. Advertising

  3. Martin Honnen wrote:
    > Khai Doan wrote:
    >> I am using Selenium, a javascript framework for automated testing of
    >> web application. The problem occurs when there is a server side HTTP
    >> redirect. Selenium would detect that a new page is loaded, proceed to
    >> the next command which then fail because the browser is carrying out
    >> the redirect. So, is it possible to use javascript on the browser
    >> side (Firefox 2) to get the http response status code?

    >
    > If you use XMLHttpRequest to make an HTTP request then you can read out
    > the status and statusText properties:
    > http://developer.mozilla.org/en/docs/XMLHttpRequest


    XHR handles server-side redirects transparently, so it cannot be used to
    detect whether a redirect took place. The value of the status property is
    either a success status code (2xx) or an error status code (4xx or 5xx)[1],
    never that of a redirect (3xx).


    PointedEars
    ___________
    [1] It may be also 0 when using XHR to access the local filesystem directly.
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, May 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike C
    Replies:
    1
    Views:
    495
    pythonhda
    Feb 16, 2004
  2. Richard Eibrand

    http status response

    Richard Eibrand, Apr 15, 2005, in forum: Python
    Replies:
    0
    Views:
    399
    Richard Eibrand
    Apr 15, 2005
  3. Replies:
    0
    Views:
    422
  4. Amit Bobade
    Replies:
    1
    Views:
    510
    7stud --
    May 27, 2011
  5. Thomas 'PointedEars' Lahn

    [FYI] MSXML HTTP translates response status code 204 to 1223

    Thomas 'PointedEars' Lahn, Sep 7, 2009, in forum: Javascript
    Replies:
    4
    Views:
    369
    Diego Perini
    Sep 16, 2009
Loading...

Share This Page