How could I be confused when your example does exactly what
I said, i.e., you use an <img> tag to run a script.
Er, no. You said you thought it was the *only* way.
My point is that as an html file is loading into a browser,
there are only a few things that can appear in that file
that will cause the browser to (indirectly) run a script
located on some other machine.
You won't be running your javascript on my browser anyway. Not until
you've given reason to believe that executing the js is more
beneficial to me than the risks which it involves.
One is some javascript function, the other is an image tag that
contains -- as does your example -- a src file which is really a
Perl script.
I'm sorry to have to say this, but "you are confused". At least, on
the evidence shown here.
I've always found that the best way to cope with complex problems
(aside from putting the PerlTroll into the killfile, since it only
creates confusion wherever it chooses to participate) is to divide the
solution into well-defined parts, and understand how each one works;
before assembling the parts into a coherent whole.
Getting back to my original post,
Well, getting back to your -original- post, you got an appropriate
answer to the question which you asked. But that unfortunately
(AFAICS) only demonstrated that you'd asked the wrong question, since
whatever it was that you *really* wanted to achieve had not been
revealed at the outset.
I want that script to do something on my server and then -- only if
it has to -- return a graphic.
I don't see anything there which needs to involve client-side
javascript. So either you aren't being candid with us, or you're
confused as to the need for some client-side js.
I'd rather it do nothing, but I don't know
if I can return a 505 header without confusing the browser,
which is expecting a graphic.
I can't help worrying that the more I read your posting, the more
confused I get. What is it - i.e in real world terms, not in terms of
whatever partially implemented draft solution that you had in mind -
are you trying to achieve?
But let's say I have to return a
graphic. One poster said I should just write binary to STDOUT.
Actually, if the result is already accessible on the server, it's
probably better to issue a status 302 redirect to its URL. But the
answer you got wasn't by any means wrong - it all hinges on what
you're trying to achieve, and that still seems to be a mystery...
That doesn't sound quite right. Another (two) say I should create
an image/gif header and then write binary.
Oh come on, be reasonable. If you're going to return a competent
response to a CGI script, then it's taken for granted that you need to
return a Content-type header first. I'm sure your informant assumed
that you would know that.
But when does the browser know the data stream has ended?
That's an interesting point, but not for the reason that you seem to
think. If the server actually knows the content length, then some
optimisations are feasible. And that's one of the points on which an
HTTP redirect could be helpful (keyword: cacheing). But it's not an
absolute requirement.
With regular html files it sees </html>,
Here you're at quite the wrong protocol layer of the network
or a length value in the header.
That part is OK, but it isn't mandatory.
I could simply try all these things, but it's more fun trying
to emulate Middle Age monks who insisted they could divine
the number of teeth in a horse's mouth by theological speculation
rather than by dissecting the darn thing.
Our equivalent would, I suppose, be to read the protocol
specifications ;-)
Keep in mind that you're returning a CGI response (which is properly
the topic of the CGI specification, see the CGI RFC draft which, for
whatever reason, seems to be getting nowhere at the moment, but is the
nearest we have to a specification). On the basis of which the HTTP
server will create an HTTP response, see RFC2616 for the applicable
details of /that/.
But these minutiae seem, at the moment, not to be what you need:
rather, you seem to need advice at a higher level, how to achieve
whatever it was (as yet unstated, AFAICS) that your whole process is
meant to achieve.
good luck