Ajax.updater 's parameters
Ajax.Updater
object开发者_开发知识库,
new Ajax.Updater(container, url[, options]);
the first parameter is the id for the HTML element, and the second is a 'url', can it be another function or another page or what?
new Ajax.Updater('datetime', '/cgi-bin/timer.cgi', {
method: 'get',
insertion: Insertion.Bottom
});
Here is the content of timer.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$datetime = localtime; print $datetime; print "
";what is exactly a 'cgi' and cant we use a normal function?!
the purpose of the Ajax.Updater function is to query your server for information, but without reloading the page. The URL you give it indicates what information you want queried from the server.
In this case, the URL points to a CGI script, which is just an executable file on your server (see this wikipedia article for more info on CGI scripts.) When you call that URL the script will execute and the result of running it will be returned. You can test this by visiting that URL with your web browser. The script you gave simply prints the local time of the server.
So the full example here is calling a URL that returns the local time of the server and inserts it at the bottom of the page. You could write a "normal" javascript function to append the time to the bottom of the page, but that would be the time of the client side computer. In this case you are appending the server time, hence you need to call the CGI script.
精彩评论