Applied Math & Computer Science Lab
Data Analysis, Optimization & Mathematical Modeling, Artificial Intelligence, Neural Net For Everyday Life Applications
AI/Data Mining Links Online Free Courses Online Bookstore AMCSL Forum Submit Link New Additions Archive
Practical Data Mining Courses      Get Certificate of Completion Now for Free   
Search the Web:    

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:
OnKeyUp="do_lookup(['input_text','NO_CACHE'],['out_layer0','out_layer1','out_layer2','out_layer3']);"
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
OnKeyUp="do_lookup(['input_text','NO_CACHE'],['out_layer']);load_list();"

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.

References



1. Ajax example with perl, MySQL, CGI::Ajax
2. Ajax example with perl, MySQL, CGI::Ajax (multiple output, souce code)
3. Ajax example with perl, MySQL, CGI::Ajax (using hidden div, souce code)
4. Ajax example with perl, MySQL, CGI::Ajax (souce code)
5. Comments, suggestions, feedback