Server communication without page reload?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kurita Kinoshita

    Server communication without page reload?

    I'm trying to find a way to have a script communicate with a server
    without having to load a new page. The idea is to have the server act
    as a simple wrapper for a database, letting the client do that icky UI
    stuff.

    I tried the obvious, putting a frame somewhere it doesn't insult the
    eye, changing its location, then accessing the new content via DOM.
    What I get from IE (6) for my pains is just a rude "permission
    denied". This even though I entered "localhost" as a trusted site in
    IE's security setting. What's amiss?

    Help from one of you pros out there would be greatly appreciated! ;-)

    TIA,
    Kurita

    cigol_detsiwt@g mx.net
  • Si Ballenger

    #2
    Re: Server communication without page reload?

    On 14 Jun 2004 07:27:31 -0700, cigol_detsiwt@g mx.net (Kurita
    Kinoshita) wrote:
    [color=blue]
    >I'm trying to find a way to have a script communicate with a server
    >without having to load a new page. The idea is to have the server act
    >as a simple wrapper for a database, letting the client do that icky UI
    >stuff.
    >
    >I tried the obvious, putting a frame somewhere it doesn't insult the
    >eye, changing its location, then accessing the new content via DOM.
    >What I get from IE (6) for my pains is just a rude "permission
    >denied". This even though I entered "localhost" as a trusted site in
    >IE's security setting. What's amiss?
    >
    >Help from one of you pros out there would be greatly appreciated! ;-)[/color]

    Not a pro, but if you don't want the page to reload, then you can
    use the status: 204 http code to tell the brouser to not expect
    to reload the page. I use it on my pages below to run programs on
    my server with out having a page refresh, in this case to operate
    pan and tilt webcams.

    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


    Comment

    • Vincent van Beveren

      #3
      Re: Server communication without page reload?

      > I tried the obvious, putting a frame somewhere it doesn't insult the[color=blue]
      > eye, changing its location, then accessing the new content via DOM.
      > What I get from IE (6) for my pains is just a rude "permission
      > denied". This even though I entered "localhost" as a trusted site in
      > IE's security setting. What's amiss?[/color]

      Thats weird,it should be accessable. Did you initialize the FRAME
      before modifying its contents? I found that you normally first need
      to load an SRC="about:blan k" before you can access its properties
      (like window.location ). The corret path to the window object of
      a frame would be document.frames[0].contentWindow. You can also use
      XML to communicate. Maybe that would even be better.

      Good luck,
      Vincent

      Comment

      • Vladdy

        #4
        Re: Server communication without page reload?

        Kurita Kinoshita wrote:[color=blue]
        > I'm trying to find a way to have a script communicate with a server
        > without having to load a new page. The idea is to have the server act
        > as a simple wrapper for a database, letting the client do that icky UI
        > stuff.
        >
        > I tried the obvious, putting a frame somewhere it doesn't insult the
        > eye, changing its location, then accessing the new content via DOM.
        > What I get from IE (6) for my pains is just a rude "permission
        > denied". This even though I entered "localhost" as a trusted site in
        > IE's security setting. What's amiss?
        >
        > Help from one of you pros out there would be greatly appreciated! ;-)
        >
        > TIA,
        > Kurita
        >
        > cigol_detsiwt@g mx.net[/color]

        There are several options that can be used. The choice depends on the
        amount and type of data that is being sent back and forth.
        1. Loading file via XMLHTTP. The following function will return any type
        of text data that you parse with client side script. The filename you
        pass is the name of your server side script and can contain query string
        that allows you to pass limited amount of data to the server:

        function getFile(filenam e)
        { oxmlhttp = null;
        try
        { oxmlhttp = new XMLHttpRequest( );
        oxmlhttp.overri deMimeType("tex t/xml");
        }
        catch(e)
        { try
        { oxmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
        }
        catch(e)
        { return null;
        }
        }
        if(!oxmlhttp) return null;
        try
        { oxmlhttp.open(" GET",filename,f alse);
        oxmlhttp.send(n ull);
        }
        catch(e)
        { return null;
        }
        return oxmlhttp.respon seText;
        }

        2. Similar to the method above you can dynamically create a script node:

        function loadJS(filename )
        { scriptNode = document.create Element('script ');
        scriptNode.src = filename;
        scriptNode.type = 'text/javascript';
        (document.getEl ementsByTagName ('head'))[0].appendChild(sc riptNode);
        }

        Again filename is your server side script and can contain query string
        as well. The difference is that the server side script has to return
        javascript (make sure you set the MIME type header to
        "text/javascript"). Compared to the first method you receive data ready
        to be used.

        3. If you have siginificant amount of data to pass to the server, you
        would need a hidden iframe so that you can use POST method.

        --
        Vladdy

        Comment

        Working...