开发者

Ajax.updater 's parameters

as i said in my title am learning about Ajax and i have a little question about it, i was looking through some examples about the 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜