Execute web page without loading

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

    Execute web page without loading

    I'd like to build a function that is executed when someone clicks on an
    image. Once clicked, I need some parameters passed to a URL which PHP
    will accept and deal with database connections. Sounds simple, and is
    simple. The only thing that stumps me is that I do not want that PHP page
    loaded anywhere that someone would see it. And preferably no frames if
    possible.

    Any suggestions?

    ~ Matthew
  • HikksNotAtHome

    #2
    Re: Execute web page without loading

    In article <pan.2003.09.11 .00.37.19.69872 0@syr.edu>, Metnetsky
    <mimetnet@syr.e du> writes:
    [color=blue]
    >I'd like to build a function that is executed when someone clicks on an
    >image. Once clicked, I need some parameters passed to a URL which PHP
    >will accept and deal with database connections. Sounds simple, and is
    >simple. The only thing that stumps me is that I do not want that PHP page
    >loaded anywhere that someone would see it. And preferably no frames if
    >possible.
    >
    >Any suggestions?
    >
    >~ Matthew[/color]

    Set an image tags src attribute to the php page, then hide the image.
    --
    Randy

    Comment

    • Thomas

      #3
      Re: Execute web page without loading

      I think that you're talking about javascript remoting. I also wish there
      was a way to do this. Ideally we could have a php script that reports db
      data and have javascript get this data from a url. The only problem is that
      if anyone was to send their browser directly to the url that reports the db
      data they'd see all the data returned from the db and not the data that we
      want them to see on the calling JS page. Let me know if you find any
      answers. I've been working on this one for weeks.

      Tom

      "Metnetsky" <mimetnet@syr.e du> wrote in message
      news:pan.2003.0 9.11.00.37.19.6 98720@syr.edu.. .[color=blue]
      > I'd like to build a function that is executed when someone clicks on an
      > image. Once clicked, I need some parameters passed to a URL which PHP
      > will accept and deal with database connections. Sounds simple, and is
      > simple. The only thing that stumps me is that I do not want that PHP page
      > loaded anywhere that someone would see it. And preferably no frames if
      > possible.
      >
      > Any suggestions?
      >
      > ~ Matthew[/color]


      Comment

      • Code Ronin

        #4
        Re: Execute web page without loading

        Metnetsky <mimetnet@syr.e du> wrote in message news:<pan.2003. 09.11.00.37.19. 698720@syr.edu> ...[color=blue]
        > I'd like to build a function that is executed when someone clicks on an
        > image. Once clicked, I need some parameters passed to a URL which PHP
        > will accept and deal with database connections. Sounds simple, and is
        > simple. The only thing that stumps me is that I do not want that PHP page
        > loaded anywhere that someone would see it. And preferably no frames if
        > possible.
        >
        > Any suggestions?[/color]

        Sure. The <script> element allows you to specify a URL in the src
        attribute. Most people just put [somefile].js, but it can actually be
        something like "getCustomerDat a.php?nameToFin d=met&searchTyp e=leading".
        The key is that the PHP page (or ASP, JSP, or whatever) must return
        JavaScript, not HTML, because it is going to be fed to the JavaScript
        interpreter. That solves the first problem, which is how to get
        information from the server to the page without causing it to refresh.

        The next problem is how to dynamically invoke that method.

        var nameSearchEleme nt;
        var nameSearchResul t;
        function doNameSearch ( nameToSearch ) {
        if ( nameSearchEleme nt != null ) {
        document.body.r emoveChild ( nameSearchEleme nt );
        nameSearchEleme nt = null;
        }
        nameSearchEleme nt = document.create Element ( "SCRIPT" );
        nameSearchEleme nt.src = "getCustomerDat a.php?nameToFin d=" +
        encodeURICompon ent ( nameToSearch ) + "&searchType=le ading";
        document.body.a ppendChild ( nameSearchEleme nt );
        }
        function doNameSearchCom plete ( ) {
        // process the nameSearchResul t object
        }

        The doNameSearch function creates the script element, attaches it to
        the current document, which in turn causes the browser to ask the
        server for the source of the script element. This establishes
        communication back to the server and allows you to retrieve the
        results.

        The server code must return valid JavaScript code. In this example, I
        have created a global variable "nameSearchResu lt" so I know where to
        look for the results of the search. It is up to you to define how to
        structure that data. This example also defines a callback function,
        "doNameSearchCo mplete", used to signal that the operation is complete.
        So, for example, the page could generate the following code:

        nameSearchResul t = {
        numNamesFound: 0,
        error: "Database currently unavailable"
        };
        doNameSearchCom plete ( );

        The last line invokes the callback function, indicating that the
        server roundtrip is complete. Unfortunately, the database was down...

        The good thing about this process is that it does not require
        plug-ins, ActiveX objects, proprietary calls to internal components,
        etc. Just good, old DHTML. The extra sweetener is that you get raw
        data as executable code, not HTML or XML that has to be parsed and
        then reformatted by other code.

        Hope that helps.

        Comment

        Working...