Ajax example with perl, MySQL, CGI::Ajax (improvements)
Ajax programming allows to develop more interactive web pages and put more intelligence to web page.
In the previous article [1] we considered how it can be implemented with perl , CGI::Ajax module, MySQL database.
CGI::Ajax module make ajax programming much easy for us. The example script created before could output only one clickable entry
on the div layer. In many real tasks we need muliple output. For example when someone is using search box we want to show several
suggestions
It turn out that CGI::Ajax can easy to do this. We need to modify the line that calls our do_lookup function as following:
As we can see CGI::Ajax allows to output to multiple layers. The perl function now should return array.
The link to source code to this script can be found on the bottom on this page.[2]
There is another way that I tried to use but it did work exactly as I wanted. I tried to put all output from do_lookup function in one hidden div layer,
and then call another javascript function load_list to load this output to HTML select listbox. Here is the example line
It works fine except that there is some delay. The listbox is loaded but only when one more Key is pressed.
For example, listbox should be loaded after I type perl in text box. But with this script I need type perlX to get loaded listbox.
'X' is any letter (any keyUp event). If someone knows how to resolve this welcome to put your suggestions.[5]
Meanwhile I put this script [3] since it could be useful in some situations and it shows how listbox can be dynamically
populated from div content.
Thus we saw how CGI::Ajax can be used if need mutiple output.