Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Passing data back to calling page

by mortalhero (Novice)
on Oct 19, 2009 at 20:32 UTC ( #802082=perlquestion: print w/replies, xml ) Need Help??

mortalhero has asked for the wisdom of the Perl Monks concerning the following question:

I am still quite a novice at this. I was succeful at sending numbers from my "index.htm" page to a file called "testscript.pl" which contains my secret formula. I now want the script to return the answer to the same "index.htm" page, but the response clears "index.htm" and creates a new page called "testscript.pl". I don't want to clear the original .htm page. I simply wnat to present the answer in it some how. I used a form to send the data to the script file, but there doesn't seem to be a form for receiving data back from a script file. Is what I'm trying to do even possible?

Thank you

Replies are listed 'Best First'.
Re: Passing data back to calling page
by cormanaz (Deacon) on Oct 19, 2009 at 23:58 UTC
    Here is a simple AJAX example that uses Perl for the backend. Like DStaal said, that's what you need to do exactly what you want.

    OTOH if you don't have some good reason to keep the same page around, you could just use Perl to generate the HTML to begin with and reload the whole thing when you need the new data. Here is a tutorial for that.

      Thanks guys. I thought I was missing something very simple. It was driving me crazy. Now I know I need to change my strategy.

      Thanks again

Re: Passing data back to calling page
by DStaal (Chaplain) on Oct 19, 2009 at 20:54 UTC

    Not without some Javascript trickery on the page, no. HTML pages render when they are loaded, and are static from then on. You'll either need to load the page again, (which to the browser is a new page) or find some AJAX snippet which does what you want.

    Basically: HTML is not designed that way. This makes what you want very difficult.

Re: Passing data back to calling page
by ww (Archbishop) on Oct 20, 2009 at 01:48 UTC

    Actually, you can do pretty close to what you ask without using AJAX or similar... so long as you're not concerned about the change in the filename/URL.

    If that's so, simply include the original renderable content of index.html, from immediately after the <body> tag to just before the </body> tag, replacing the input form with the an appropriately formatted section to render the "answer."

    This has some drawbacks, particularly if your original page is very large, but it also has the advantage of sidestepping problems for the visitor who chooses to browse with javascript disabled and it will give the visitor the impression that s/he is still on the same page (except for the contents of the address bar).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://802082]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-05-26 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?