AJAX app will not make call on Safari and FireFox, works fine on Internet Explorer, any ideas?

Discussion in 'ASP .Net' started by JDeats, Sep 11, 2007.

  1. JDeats

    JDeats Guest

    >From my development envrionment (i.e. a single WinXP notebook PC) I
    have a basic AJAX application that is making the call to a Windows
    Form page that just returns the request back to the AJAX client from
    the JavaScript HttpXMLRequest


    protected void Page_Load(object sender, EventArgs e)
    {
    string txt = "";
    string input = null;
    StreamReader sr = new StreamReader(Request.InputStream);
    while ((input = sr.ReadLine()) != null)
    {
    txt += input;
    input = null;
    }

    sr.Close();
    sr.Dispose();


    Response.Write(txt);
    Response.End();

    }

    In the onreadystatechange event, once the request is returned I am
    performing a simple JavaScript alert() to display back the response.
    This works fine from IE when it's calling a local server either IIS or
    from VS.NET 2005's ASP.NET development Server on port 2160. However
    if I try to make the call to either of these servers from FireFox or
    Safari it appears the call to HttpXMLRequest never goes through.

    I understand there is a cross-domain restriction on HttpXMLRequest
    calls in Safari and FireFox that is handled differently in IE, I
    suspect this has something to do with the problem.... Any advice?
     
    JDeats, Sep 11, 2007
    #1
    1. Advertising

  2. JDeats

    bruce barker Guest

    Re: AJAX app will not make call on Safari and FireFox, works fineon Internet Explorer, any ideas?

    ie will also enforce cross doamain, unless the source is trusted. often
    in dev, the html source is trusted, where it will not be from a hosted
    server. then IE will act like forefox and safari

    -- bruce (sqlwork.com)

    JDeats wrote:
    >>From my development envrionment (i.e. a single WinXP notebook PC) I

    > have a basic AJAX application that is making the call to a Windows
    > Form page that just returns the request back to the AJAX client from
    > the JavaScript HttpXMLRequest
    >
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > string txt = "";
    > string input = null;
    > StreamReader sr = new StreamReader(Request.InputStream);
    > while ((input = sr.ReadLine()) != null)
    > {
    > txt += input;
    > input = null;
    > }
    >
    > sr.Close();
    > sr.Dispose();
    >
    >
    > Response.Write(txt);
    > Response.End();
    >
    > }
    >
    > In the onreadystatechange event, once the request is returned I am
    > performing a simple JavaScript alert() to display back the response.
    > This works fine from IE when it's calling a local server either IIS or
    > from VS.NET 2005's ASP.NET development Server on port 2160. However
    > if I try to make the call to either of these servers from FireFox or
    > Safari it appears the call to HttpXMLRequest never goes through.
    >
    > I understand there is a cross-domain restriction on HttpXMLRequest
    > calls in Safari and FireFox that is handled differently in IE, I
    > suspect this has something to do with the problem.... Any advice?
    >
     
    bruce barker, Sep 11, 2007
    #2
    1. Advertising

  3. JDeats

    JDeats Guest

    On Sep 11, 2:44 pm, bruce barker <> wrote:
    > ie will also enforce cross doamain, unless the source is trusted. often
    > in dev, the html source is trusted, where it will not be from a hosted
    > server. then IE will act like forefox and safari
    >
    > -- bruce (sqlwork.com)
    >


    Bruce,

    Thanks for your help.

    So I guess my question is: how does the cross-domain restriction
    effect non-IE browsers when you're developing and testing on
    localhost. There is no domain server present in this case as I'm not
    running a domain server on my XP Pro notebook where all this is
    occurring, but I do need to be able to test from non-IE browsers on my
    dev environment.

    req.onreadystatechange = processReqChange;
    req.open("POST", "SendIt.aspx", true);
    alert(req.readyState); // this returns 1 on all browsers as expected,
    indicating the open command was a succes
    req.send("<b>data</b>");

    So after the send call is made the processReqChange function gets
    called.... From inside processReqChange I can test req.readyState and
    it equals 4 as expected.... however if I try to get the value of
    req.status an exception is thrown in FireFox, below is the code with
    comments explaining what is happening at various points.

    function processReqChange() {

    alert("process req changed");
    // this called when the page loads by IE, FireFox and Safari..... It
    is called again after the req.send(...) command is issued on FireFox
    and IE, but not on Safari.


    if (req.readyState == 4) {
    // only if "OK"

    try
    {
    var s = req.status;
    alert(s); // I can only get to this point with Internet
    Explorer.

    } catch (e) {
    alert("failed to read status");
    // this catch is always trigged from FireFox, again with
    Safari this event handler methid is never even triggered after the
    req.send...
    }


    -Jeremy
     
    JDeats, Sep 11, 2007
    #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. Replies:
    4
    Views:
    5,394
    Jonathan N. Little
    Dec 5, 2005
  2. Jon Prisbe
    Replies:
    0
    Views:
    138
    Jon Prisbe
    Feb 15, 2008
  3. Replies:
    4
    Views:
    258
    Randy Webb
    Feb 18, 2006
  4. Replies:
    3
    Views:
    110
  5. gray_slp
    Replies:
    3
    Views:
    128
    Geoffrey Summerhayes
    Jun 27, 2007
Loading...

Share This Page