Hi everyone,
I’d like to use a ruby script to generate an image (directed graph) and
sand it to an ajax-like javascript script that display the image in the
browser.
I tryed to do it but what the browser display only a lot of strange
characters. I think it’s a headers problem but I really don’t know how
to solve it.
When I run the script in a shell and redirect the input to a file, the
generated image is good
What is the best way to send the image to the browser?
Any idea is welcome,
thanks in advance.
generated image is good
main = g.add_node( “main” )
var request = false;
}
if (request.readyState == 4) {
var url =“nph-script.rb”;
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
################################################
Maybe you want to use the CGI class.
require ‘cgi’
cgi = CGI.new
cgi.header[‘Content-Type’] = ‘image/png’
cgi.print cgi.header
generated image is good
main = g.add_node( “main” )
var request = false;
}
if (request.readyState == 4) {
var url =“nph-script.rb”;
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
################################################
Actually forgot what i just said, you’re doing this all wrong. src
points to a url, not the actual image data. Ajax is also probably
pretty silly for this. Do this in your html:
no javascript, no ajax, just good old fashioned cgi. If you do want
this graph to be more dynamic than that, you’re going to have to
learn how the img tag works (like I said src is not image data its a
url).
Actually forgot what i just said, you’re doing this all wrong. src
points to a url, not the actual image data. Ajax is also probably
pretty silly for this. Do this in your html:
no javascript, no ajax, just good old fashioned cgi. If you do want
this graph to be more dynamic than that, you’re going to have to learn
how the img tag works (like I said src is not image data its a url).
You might be able to us JavaScript to get a reference to the desired
Image object (in document.images )and update the src property.
1)The user insert some data in a field, than press a button
2)A script receive the data and return some textual info and an image
With ajax I can make an interface with an instant textual answer from
the system (without page refresh), but I’d like to do the same thing
with the image.
If I use this technique:
The image is updated only when I refresh the page.
Ummm… maybe I simply cannot do it.