NEWBIE: CGI call or post? problem sending data to server

K

Ken Smith

Hi,

Sorry for dumb newbie question:

I have an embedded system with HTTP server that may not be completely
standard. I can successfully get the server to generate dynamic pages
using statements such as:

<!--#exec cgi="/GeneratePage.fn"-->

where GeneratePage.fn is a function in my server application. Now I
want to send data to the server without changing the display in my
browser.

I have tried using <form action="GeneratePage.fn" ......> </form>, along
with a button on the form. This works in that I can receive the data in
the GeneratePage.fn function within my server application - but the
client browser then tries to open a page called GeneratePage.fn. Is
there anyway I can send data using this 'action' mechanism, but prevent
the browser also trying to open the page specified by the action?

The other method I tried is to use an onclick event on the button. I
defined a JavaScript function for the on click event, and can get the
JavaScript to execute (I used an alert() call to check it was running).
But how do I get the JavaScript to call the GeneratePage.fn function in
my server?

Thanks for any advice.
 
K

kaeli

The other method I tried is to use an onclick event on the button. I
defined a JavaScript function for the on click event, and can get the
JavaScript to execute (I used an alert() call to check it was running).
But how do I get the JavaScript to call the GeneratePage.fn function in
my server?
DOM browsers only.
Modify this.

<URL:
http://www.ipwebdesign.net/kaelisSpace/useful_serverClientValidation.html >

Note that your function must return valid javascript with proper headers,
even if the "valid javascript" it returns is a null string that does nothing.

--
--
~kaeli~
The more ridiculous a belief system, the higher probability
of its success.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
G

Grant Wagner

kaeli said:
DOM browsers only.
Modify this.

<URL:
http://www.ipwebdesign.net/kaelisSpace/useful_serverClientValidation.html >

Note that your function must return valid javascript with proper headers,
even if the "valid javascript" it returns is a null string that does nothing.

If all he is interested in is firing the server-side code and doesn't care if it
succeeds or not, he could use:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.fn";
}
</script>

The above is much more cross-browser compatible, although it does not easily
allow for the returning of any sort of information to the browser after
GeneratePage.fn runs.
 
K

Ken Smith

If all he is interested in is firing the server-side code and doesn't care if it
succeeds or not, he could use:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.fn";
}
</script>

[I changed the GeneratePage.fn used in the previous example to
SendCommand.fn as this is more representitive of what I am attempting to
do]

Thanks for both of these suggestions. However both result in a:

GET /SendCommand.fn HTTP/1.1
HTTP/1.1 404 The requested URL was not found

transaction. Maybe this is what is required on most systems. In my
case the CGI function I want to execute is built into the servers
application executable at link time rather than a separate file. When a
form [action="SendCommand.fn" method="post"] is used the server looks in
the application executable for the SendCommand.fn function and runs it.
This is what I need to happen on the button click.

Is there a JavaScript trick I can use to perform this "post" type
operation rather than a "get" type operation? I cannot use the form
post method as this then makes the browser try to open another page, all
I want to do is send data to the server.

Thanks once again.
 
K

kaeli

Is there a JavaScript trick I can use to perform this "post" type
operation rather than a "get" type operation?

Not that I know of.
Unless you want to putz with an iframe. That would not be recommended for an
internet application because of cross-browser issues.

I think you might want an applet. You can make them nonvisible and they can
interact with both javascript and with the server, as it can use Java's
httprequest object. You'd call one of the applet's methods using javascript
with the button onclick. The applet would then send data as needed to the
server.
Something to look into.

If this is IE only (intranet), you could use ActiveX.

--
 
G

Grant Wagner

Ken said:
If all he is interested in is firing the server-side code and doesn't care if it
succeeds or not, he could use:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.fn";
}
</script>

[I changed the GeneratePage.fn used in the previous example to
SendCommand.fn as this is more representitive of what I am attempting to
do]

Thanks for both of these suggestions. However both result in a:

GET /SendCommand.fn HTTP/1.1
HTTP/1.1 404 The requested URL was not found

transaction. Maybe this is what is required on most systems. In my
case the CGI function I want to execute is built into the servers
application executable at link time rather than a separate file. When a
form [action="SendCommand.fn" method="post"] is used the server looks in
the application executable for the SendCommand.fn function and runs it.
This is what I need to happen on the button click.

Is there a JavaScript trick I can use to perform this "post" type
operation rather than a "get" type operation? I cannot use the form
post method as this then makes the browser try to open another page, all
I want to do is send data to the server.

Thanks once again.

Hmm. Maybe I'm misunderstanding what you want to do, but assuming you don't need to
pass any parameters to GeneratePage.fn, why not:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.html";
}
</script>

and in GeneratePage.html:

<!--#exec cgi="/GeneratePage.fn"-->

In other words, set the Image#src to a real file that _does_ exist, that file can call
the function you want. It doubles your chances of something going wrong but the whole
(new Image()).src thing is dependant on JavaScript and sort of a hack anyway.
 
K

kaeli

Hmm. Maybe I'm misunderstanding what you want to do, but assuming you don't need to
pass any parameters to GeneratePage.fn, why not:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.html";
}
</script>

He can't do that because GeneratePage.fn is NOT a real page (404).
It's like FP extentions, but not. Or like one method of a servlet. The server
specifically is set to to understand form submission to that URL as mapped to
a different resource that has a function of the same name in it. It is not by
itself a retrievable URL.

--
 
G

Grant Wagner

kaeli said:
He can't do that because GeneratePage.fn is NOT a real page (404).
It's like FP extentions, but not. Or like one method of a servlet. The server
specifically is set to to understand form submission to that URL as mapped to
a different resource that has a function of the same name in it. It is not by
itself a retrievable URL.

That's why the post you replied to suggested he use:

<script type="text/javascript">
if (window.Image) {
(new Image()).src = "/GeneratePage.html";
}
</script>

and in GeneratePage.html:

<!--#exec cgi="/GeneratePage.fn"-->

Now the JavaScript retrieves a real URL, that real server resource calls the server-side
function. Assuming no parameters need to be passed, I think this should work.
 
K

kaeli

and in GeneratePage.html:

<!--#exec cgi="/GeneratePage.fn"-->

Oops, I can read. I swear.
Now the JavaScript retrieves a real URL, that real server resource calls the server-side
function. Assuming no parameters need to be passed, I think this should work.

Hrm...

I hope he posts if it does. Neat trick.

--
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top