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;




    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. Advertisements

  2. JDeats

    bruce barker Guest

    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 barker, Sep 11, 2007
    1. Advertisements

  3. JDeats

    JDeats Guest


    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

    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"

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

    } 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

    JDeats, Sep 11, 2007
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.